Public Group

# Check Collision in advance

## Recommended Posts

hello!

it's my first post here so... i want to say just that my english it too bad so i'll do my best to be clear as possible as i can.

i'm a student so i'm trying to understand a lot of stuff, in this case i have to check in advance if my gameobject will fall off the ground after a certain distance, for example i'll attach here a screenshot to be more clear, asl you can se if my gameobject is continue moving forward will fall of the ground, what i want to do is check in advance it then change some stuff to avoid it.

someone know how to do it and can help me?

thank's you in advance

##### Share on other sites
Posted (edited)

Find a normal vector from wall to closest point on object. Now project speed of your object to it normal. As result you will have a time required to reach a wall. Now project speed to wall direction vector. From distance from normal base point to end of wall you will find is your object will hit wall or miss it movimg with current speed. For circle as object and linear wall it works simple.

By other world build a basis on closest to object wall point , alligned allong a wall, convert object speed vector to its basis and check is ray built on object velocity vector started from closest to wall object point intersect a wall segment and t of intersection will give a time to impact in case in case intersection exists.

For cilcular shaped object Minkowskiy sum make it task much simply. You can just shift walls inside a rooms by radius of circle and use a center of circle as closest to wall object point.

It works simple for constant velocities. But for accelerated movement like a gravitation and so on it much harder task becouse trajectory of body is not linear and require to solve quadric or higher power equation numerically.

Its  problem complitely described by Brian Mirtich into his PhD tesis

Edited by Fulcrum.013

##### Share on other sites

so, maybe i got it.

in my case i should chose a point in a certain distance from my object on it's forward direction, now i have to project my speed to that "poin" to let it simple i'lkl call it "p', so i'll get in how many time it reach the target, then the problem is... for example, as you can see from the picture that i attached before, there is no 'wall' my object will move only in a plane space, how i can detect if there is a plain in a certain p point or not?

right know i can let move my object on a plane, by getting the distance between the plane and my object on the Z axis, then set the the position of my object by getting the closes z axis plane Y then add some value to it, but it's not so accurate if the scale of the plane will change, so i'm also looking a diferent way to accomplish it.

i hope that i was understandable.. thank's you again for your help!

##### Share on other sites
Posted (edited)
9 minutes ago, Mirko Rossetti said:

how i can detect if there is a plain in a certain p point or not?

Any wall segment have a length so you can determine is projection of object point and a intersection fit to length of wall segment. In whole for closed convex-shaped room (nav poly) object anycase will hit one of walls. Calculating a  t of hit for each wall of the room  you can easily detect wich wall it will hit first. For doors/portals to other rooms that a same walls but marked as walckable trought it works same - you have to trace ray tru neiborghud room by same way until hit a wall, in case it not enougth to just detect is it come thru the door/portal or hit a wal.

Edited by Fulcrum.013

##### Share on other sites
Posted (edited)

Green is circle velocity vector parallely shifted to closest to wall point marked by black rombus. Red is approach vector i/e/ projection of velocity to wall normal. Circle can hit a linear wall only by closest point. For other wall closest point will be found somewhere else on circle. Its intersection point of normal to wall build from centre of circle with circle. Minkowsky sum shifting a walls just collapse circle to single point, becouse shift  task by radius along a normal for each wall.

Edited by Fulcrum.013

##### Share on other sites
1 hour ago, Mirko Rossetti said:

there is no 'wall' my object will move only in a plane space,

Border lines of navpoly usually represent a vertical walls projected to floor plane.

##### Share on other sites

thenks you!

maybe i got it, i'll try to do it and let you know the results by reply on this post.

actually to get the character position on the plane i'm using this method, is the best way to accomplish it?

		float fixedY;
Vector3 playerPos = new Vector3 ( 0.0f, 0.0f,transform.position.z);
Vector3 planePos = new Vector3 (0.0f,0.0f,plane.transform.position.z);
float distance = Vector3.Distance(playerPos,planePos);

if (distance <= 1)
{
fixedY = plane.transform.position.y + 0.1f;
transform.position = new Vector3(transform.position.x,fixedY,transform.position.z);
}

##### Share on other sites
Posted (edited)

For player controlled character you can just to store distances vectors to all walls of current navpoly and project a step to each of its to check is character hit a wall. It nearly same that check is circle inside AABB but works for any convexive polygons, not for just AABB. For AI-controlled character better solution to prebuild path that warrantied not hit a walls to avoid a collision checks for each NPC. It again can be done using a set of connected navpolys and simplified by minkowskiy sum. Its trick built over fact that navpoly is convexive, so any segment drawn betwin any point inside navpoly can not intersect a walls.

Edited by Fulcrum.013

##### Share on other sites
43 minutes ago, Mirko Rossetti said:

actually to get the character position on the plane i'm using this method, is the best way to accomplish it?

Really a'm dont use a unity so for me planes is planes and  vectors is vectors. I just move characters something like

	PrevPos = Pos;
Pos+=Step;
if (! AcceptiblePos(Pos)) Pos=OldPos;


##### Share on other sites

i see, actually is my target, right now i'm starting to do stuff without unity components, then i'll try to go without unity, and use it just for test...

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 14
• 9
• 10
• 12
• 17
• ### Forum Statistics

• Total Topics
632904
• Total Posts
3009150
• ### Who's Online (See full list)

There are no registered users currently online

×