Jump to content
  • Advertisement
Sign in to follow this  
Meshboy

Maybe more programming than math or physics but here it goes...

This topic is 3715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

public types.cPlane ClosestPlane(Vector3 mPos) { float LengthToPlane = 100; types.cPlane temp = new types.cPlane(); for (int i = 0; i <= planes.Count - 1; i++) { if (Vector3.Length(planes.ClosestPointOnPlane(mPos) - mPos) <= LengthToPlane) { temp = planes; LengthToPlane = Vector3.Length(planes.ClosestPointOnPlane(mPos) - mPos); } } return temp; } This method gets the closest Plane(segment) calculated by the destination of the player, now my problem is that if i am in a corner i need to push my player back if collision is occured with both planes that are within length < 0, i just don´t know how to get both planes? should i create an array or something to store those two planes in?

Share this post


Link to post
Share on other sites
Advertisement
Yes, use an array as input parameter ! Something like this:

public int ClosestPlanes(Vector3 mPos, cPlane* mPlanes, int mMaxPlanes)
{
.. check plane and get distance d

.. insert plane with insertion sort into mPlanes

.. return number of found planes
}

This way you could use it:

cPlane myPlanes[2];
int planeCount = ClosestPlanes(myPos, myPlanes,2);
if(planeCount>0)
{
..
}

--
Ashaman

Share this post


Link to post
Share on other sites
ideally you want to pass in a position for the character, and a direction vector (whose length is the distance you want to move this frame). Then treat the character position + direction as a ray, and find which plane it hits first (i.e. the one with the shortest distance).

When you have that plane, move the character upto the intersect point, and rebound (the remaining) direction vector off that plane. Repeat until the direction vector is zero.

That is basically the only reliable way of dealing with the problem. Simply testing for closeness to the plane does not solve the sollision problem. Typically once you have the simple point/ray method working, you then extend the idea to sweep a sphere or other collision shape along the ray instead.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!