Advertisement

ColDet lib -> ground - player

Started by October 15, 2002 03:47 AM
5 comments, last by digitalerr0r 22 years, 4 months ago
Hello, im using the ColDet lib to test for a collision. I have tested if the player(.x file) hits the ground(.x file), but what then? Im testing with this loop: float gravity = 0.981f; if(m_Collision_betwen_player_and_ground) player_pos.y += gravity; else player_pos.y -= gravity; And the player stops on the ground, but its "hopping/jumping" like &/(%, and if I walk down my player walks trough the ground(becouse the z increases more than the groundnormal force pushes the player upwards) btw: the ground is bumpy This was harder to explain with words than I tought, but hope you still understand my problem. Thank you for your time! [edited by - DigitalErr0r on October 15, 2002 5:16:55 AM]
For one thing, you would want to add gravity to the player''s velocity, not position.
Advertisement
Ahh, thank you, Il see what I can do, didnt think about that, lol..!!
hmm..

[edited by - DigitalErr0r on October 16, 2002 9:54:37 AM]
Ok, its better now, but I just cant understand how this is done =((

//(every frame)
m_Camera.AddToVelocity(D3DXVECTOR3(0.0f, -gravity, 0.0f));


if(m_Coll_betwen_player_and_ground) {
m_Camera.AddToVelocity(D3DXVECTOR3(0.0f, gravity, 0.0f));
}

And, the gravity that is pulling the object down, is pulling on the cameras y axis. If you turn upside down, the camera will be pulled upwards...how can I fix this? What point should I pull the object down on? I have attached a player(player xyz pos = cam xyz pos), shoud I make the force to be pulled on the player insted of the camera? so cam xyz = player xyz?

I know I need better physic knowledge, and Im taking a course at school.
the code is goes like this now:
if(m_CollPlayer) {
m_Camera.AddToVelocity(D3DXVECTOR(0.0f,gravity, 0.0f));
//m_Camera.SetVelocity(D3DXVECTOR3(0.0f, 0.0f, 0.0f));
//Camera.m_vVelocity.y = 0.01f;
}

(now it stays still on the ground, but if i walk f, I can add everything I need to the Cameraclass, but dunno what =( ).
Advertisement
I'm not familiar with your collision library, but I would think the way to do what you're attempting would be something like this:

h = y value of intersection between line(Camera.Pos.x, 1000000, Camera.Pos.z)-(Camera.Pos.x, -1000000, Camera.Pos.z) and ground

if(Camera.Pos.y<=h+PlayerHeight)
{
Camera.Pos.y=h+PlayerHeight;
Camera.Vel.y=0;
}
else
Camera.Vel.y+=gravity;


This way, you only need to test one line against the ground instead of the whole player mesh.

[edited by - Bagel Man on October 16, 2002 4:40:00 PM]

This topic is closed to new replies.

Advertisement