Page 4 of 5

Re: "A FPS Game" Online Game

Posted: Sun Feb 01, 2009 3:11 am
by LeonBlade
I'm trying to take the difference of the distances between the X and Z of the two objects.
Then seeing if the distance is less than the radius.

But this doesn't always work, because sometimes the values are negative...

Re: "A FPS Game" Online Game

Posted: Sun Feb 01, 2009 3:13 am
by Ginto8
LeonBlade wrote:But this doesn't always work, because sometimes the values are negative...
Create an absolute value function, like this:

Code: Select all

int abs( int number )
{
    if( number < 0 )
       return -number;
    return number;
}

Re: "A FPS Game" Online Game

Posted: Sun Feb 01, 2009 3:43 am
by LeonBlade
Wow... I can't believe I never thought of that haha.
It works too!!!

Thanks so much dude, your the best!

Re: "A FPS Game" Online Game

Posted: Sun Feb 01, 2009 3:58 am
by Ginto8
LeonBlade wrote:Wow... I can't believe I never thought of that haha.
It works too!!!

Thanks so much dude, your the best!
No problem, glad I could help. :)

Re: "A FPS Game" Online Game

Posted: Sun Feb 01, 2009 4:32 am
by LeonBlade
I'm almost there...
So, what I'm doing is setting my Velocity to 0 when I encounter a collision.

Code: Select all

private void CheckCollisions()
        {
            for (int i = 0; i < objects.Length; i++)
            {
                float delta_x = abs(player.Center.X) - abs(objects[i].Center.X);
                float delta_z = abs(player.Center.Z) - abs(objects[i].Center.Z);

                float sum = (player.Sphere.Radius * objects[i].Sphere.Radius) * 2;

                if (delta_x <= sum && delta_z <= sum)
                {
                    if (player.Velocity.X != -player.Velocity.X)
                    {
                        hit_x = true;
                    }
                    else
                    {
                        hit_x = false;
                    }
                    if (player.Velocity.Z != -player.Velocity.Z)
                    {
                        hit_z = true;
                    }
                    else
                    {
                        hit_z = false;
                    }
                }
            }
        }
Now what I'm doing is making it so you can only move in the set velocity if it's negative of it's current...
But that isn't working right... it was earlier...

Re: "A FPS Game" Online Game

Posted: Sun Feb 01, 2009 8:59 am
by M_D_K
You should really include Y axis checking in that.

Re: "A FPS Game" Online Game

Posted: Sun Feb 01, 2009 10:54 am
by LeonBlade
Yeah I know, but I'm not doing Y collision just yet.
But that shouldn't effect it in the way that it does.

When you encounter an object, you stop on both X and Z axis, and then if you try to move away, it does nothing...

I'm stopping the update of the player's position, not the velocity, so you still should be able to adjust velocity and get (unstuck) but it's not working right...

Re: "A FPS Game" Online Game

Posted: Sun Feb 01, 2009 11:04 am
by M_D_K
But doesn't velocity update position?

And why did you have a variable called bleed in your update loop shouldn't you be multiplying by delta time(currentTime - lastTime).

Re: "A FPS Game" Online Game

Posted: Sun Feb 01, 2009 11:31 am
by LeonBlade
Yes Velocity Updates Position... but you can still modify Velocity even when I lock the Position.

And I don't know how to get currentTime - lastTime so I just bleed off the velocity like that.

Re: "A FPS Game" Online Game

Posted: Sun Feb 01, 2009 5:34 pm
by MarauderIIC
<cmath> has abs() by the way, which is an absolute value fn.

Re: "A FPS Game" Online Game

Posted: Sun Feb 01, 2009 5:38 pm
by LeonBlade
M_D_K helped me out big time with some stuff!
So I'm getting there, thanks again M_D_K!

Re: "A FPS Game" Online Game

Posted: Sun Feb 01, 2009 10:12 pm
by Aeolus
Are you going to implement guns?

Re: "A FPS Game" Online Game

Posted: Mon Feb 02, 2009 11:08 am
by LeonBlade
Aeolus wrote:Are you going to implement guns?
Lol yes... it would be pretty shitty FPS without guns don't you think? Haha :lol:
Right now still working on basic game mechanics...

Re: "A FPS Game" Online Game

Posted: Mon Feb 02, 2009 12:13 pm
by Aeolus
No i mean multi-guns.

Deagle, M-16, m-4, etc...

Re: "A FPS Game" Online Game

Posted: Mon Feb 02, 2009 12:19 pm
by LeonBlade
Oh... yeah probably, for now it will just be one gun though.