Skip to main content
GameDev.net gamedev.net
🔒 Locked

how to do sliding in 360 degrees movement

Started by mickeyren Mar 5, 2009 at 7:12 PM 5 replies 1.3k views
Original Post
mickeyren
mickeyren
Hi I have an object(plane) that moves 360 degrees in space. So far I can detect collision between the object and the obstacles. The obstacles are represented as bounding box. When I check collision i simply check if a point (position of the object) is inside the bounding box. And that's it. I'm not too sure how I can get the point of intersection - as I believe this is needed to create a sliding plane. Based from those, can you show me how I can have my object slide in 3d space in the correct direction depending on the angle of incidence? Thanks. [Edited by - mickeyren on March 5, 2009 7:50:51 PM]
mickeyren
mickeyren
Hi guys

I think I manage to gather the necessary information to generate a sliding plane by raycasting with an axis aligned bounding box. My problem now is how do i apply the new velocity vector?

So to generate the destination vector and velocity this is what i do:

Vector3 newDestinationPoint = destinationPoint - slidingPlane.getDistance( destinationPoint ) * planeNormal;Vector3 newVelocityVector = newDestinationPoint - intersectionPoint;


destinationPoint is simply position + velocity of the current player/object.

Currently, the way i move my object(plane) is relative to its last position, something like this:

if( mThrustsOn ){      Vector3 velocity = mSceneNode->getOrientation () * Vector3 (0, 0, 100 * elapsedTime);      mSceneNode->translate(velocity);}


That is without collision my problem is once I want to make sure that my ship slides when it collides with a obstacle this was my last attempt:

if(collision){   newVelocityVector *= 100;   mSceneNode->translate(newVelocityVector);}else{     mSceneNode->translate(velocity);}


But I end up stuttering my plane or it won't slide at all. Either I'm applying it wrong or I'm not generating the new velocity correctly.

Thanks.

[Edited by - mickeyren on March 7, 2009 2:41:39 PM]
JohnnyCode
JohnnyCode
your obstacles are bounding boxes? how do you slide on them then? if they are a tris geometry then just fetch the normal of colliding triangle and if the normal has a large angle with y vertical axis take the normal and just add it to the object moving vector. that will couse the object to move a bit off the surface in the direction of slide
Bob Janova
Bob Janova
Just setting the destination point of the object to the new destination point (i.e. with the collision penetration removed) will give you 'sliding' behaviour, because you enter the collision plane obliquely and are expelled perpendicularly, giving you a net movement per frame.
mickeyren
mickeyren
Quote:
Original post by JohnnyCode
your obstacles are bounding boxes? how do you slide on them then? if they are a tris geometry then just fetch the normal of colliding triangle and if the normal has a large angle with y vertical axis take the normal and just add it to the object moving vector. that will couse the object to move a bit off the surface in the direction of slide


Hi

Why do you sound like if i use bounding box i wouldn't be able to slide anymore?

Also, do I assume that the new destination point should always lie on the sliding plane?

mickeyren
mickeyren
hey guys

I have to break this down i'm still stuck.

My question is, does the new destination point will ALWAYS be on the sliding plane?
oliii
oliii
yes. That's sliding.

The typical sliding algorithm is to remove the component of the velocity along the collision plane normal.

If you have a collision time, intersection depth (if you are intersecting the box for some reason), and collision plane normal, the algo would look like...

object.velocity -= collision.normal * object.velocity.dotProduct(collision.normal); // slide velocity vector


A typical collision loop :

bool collide(Object& object, float timestep){    while(timestep > 1.0E-6f)    {        CollisionInfo collision;        bool collided = findCollision(object, timestep, collision); // find collision with object with a time limit.        // no collision detected. stop the collision detection loop        if(!collided)            break;        object.position += collision.normal * collision.penetrationDepth; // stop intersecting        object.position += object.velocity * collision.time; // move to the collision point in time        object.velocity -= collision.normal * object.velocity.dotProduct(collision.normal); // slide velocity vector        timestep -= collision.time; // reduce timestep, look for a new collison    }    object.position += object.velocity * timestep; // move object to the end of the timestep, where there is no collision}
Everything is better with Metal.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.