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

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

## 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 on other sites
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 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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634092
• Total Posts
3015437
×