msz9's picture

How do I find blocks that are in the same spot(x, y, z wise) as me?

FreeCamera.cs:
http://paste.ubuntu.com/700205/

Player.cs(it's camera.cs in the code because this is an old backup. Not much difference besides comments and the file name change though):
http://paste.ubuntu.com/700206/

Block.cs:
http://paste.ubuntu.com/700207/

Terrain.cs:
http://paste.ubuntu.com/700209/

Level.cs:
http://paste.ubuntu.com/700210/

I though I may need to post the code so I don't have to wait any longer for a response by pasting it later.

Anyway, instead of AABB crap which I don't understand, I want to be able to see "hey, there is a block in this x, y, z position" and I can see if it solid and then if it is not, you walk through it. Else, speed = 0;.
How would I find out if my x, y, z is shared by a block(which it always is, seeing how the air is filled with... air block :/)
So any ideas?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tksuoran's picture

If this is some sort of Minecraft like thing then for each (x,y,z) location there is exactly one block, thus GetBlock(x,y,z).TerrainInfo.Solid should tell you if the block at (x,y,z) is solid or not.

msz9's picture

I tried that, here is my code that failed:

Camera.cs new code:

#region Old Location
        public double preX
        {
            get { return Location.X; }
            set { Location = new Vector3d(value, Location.Y, Location.Z); }
        }
        public double preY
        {
            get { return Location.Y; }
            set { Location = new Vector3d(Location.X, value, Location.Z); }
        }
        public double preZ
        {
            get { return Location.Z; }
            set { Location = new Vector3d(Location.X, Location.Y, value); }
        }
        #endregion

FreeCamera.cs new code:

if (keyboard[Key.W] && !keyboard[Key.S]) {
                    preX -= Math.Sin(yaw) * Math.Cos(pitch) * speed;
                    preY += Math.Sin(pitch) * speed;
                    preZ += Math.Cos(yaw) * Math.Cos(pitch) * speed;
 
                    int X1 = Convert.ToInt32(preX);
                    int Y1 = Convert.ToInt32(preY);
                    int Z1 = Convert.ToInt32(preZ);
                    if (level.GetBlock(X1, Y1, Z1).TerrainInfo.Solid)
                    {
                        speed = 0;
                    }
                    else
                    {
                        X -= Math.Sin(yaw) * Math.Cos(pitch) * speed;
                        Y += Math.Sin(pitch) * speed;
                        Z += Math.Cos(yaw) * Math.Cos(pitch) * speed;
                    }
 
				}

Location being a double and GetBlock uses ints, I had to convert it. It still won't work.
If I also try MoveSpeed = 0;, it freezes me when I try to move with any key.