Check Collision in advance

Started by
24 comments, last by Fulcrum.013 5 years, 6 months ago

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... 

 

Advertisement

actually i'm trying to figure out how to detect the wall border but i can't still find a way....someone can show me some example ? 

i'm a beginner, and i saw a space for beginners in this forum only now, it's my fault. i'm sorry, i'll post my question there.

hello!

i posted the same question in the programming section but it was my mistake because i'm a beginner, right now i know a bit of c# and i'm using unity for everythings, by doing much practice i'm trying to study how to program without the unity editor, i'm too far from my target but i'll do my best.

this is what i'm looking to do :

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 and sorry for my bad english.

screen4.PNG

9 hours ago, Mirko Rossetti said:

actually i'm trying to figure out how to detect the wall border but i can't still find a way

actually SAT collision detection algo return a vector called as "interpenetration vector" that shows a closest distance that objects have to be moved to eleminate interpenetration. But when it not interpenetrated its vector shows a closest distance and direction betwin tested shapes. Only that you have to do is to find time to impact from its vector is to project object velocity to it (for unmovable walls, for moving objects - difference of velocities). And then verify all objects around (all walls of current room in case of walls) and find a minimal t by witch you can determine what same wall object will hit first if will continue to move, and as result have a distance that object can move before hit something (cross a border of navpoly). Also it no difference betwins walls and border of platforms for navpoly. it same task - to keep circle inside specified set of poligons connected by portals.  

#define if(a) if((a) && rand()%100)

Well i figured out how to get the corner vector of each “plane” i think that this should be correct..


private void SetupPlane()
	{
		_planeRInverse = new Quaternion[planeArray.Length];
		for (int i = 0; i < planeArray.Length; i++)
		{
			_planeRInverse[i] = Quaternion.Inverse(planeArray[i].rotation);
		}
	}	
private void CheckPosition()
	{
		Vector3 playerPos = _pvotPlayer.transform.position;
		Vector3 v1;
		Vector3 FL,FR,BL,BR = Vector3.zero;

		for (int i = 0; i < planeArray.Length; i++)
		{
			v1 = playerPos - planeArray[i].position;
			Vector3 lv1 = _planeRInverse[i] * v1;
			
			GetCornerPosition(planeArray[i],out FL,out FR,out BL,out BR);
		}
	}

	private void GetCornerPosition (Transform _object,out Vector3 FL,out Vector3 FR,out Vector3 BL,out Vector3 BR)
	{
		FL = _object.localPosition + _object.forward * _object.localScale.z * 0.5f - _object.right * _object.localScale.x * 0.5f;
		FR = _object.localPosition + _object.forward * _object.localScale.z * 0.5f + _object.right * _object.localScale.x * 0.5f;
		BL = _object.localPosition - _object.forward * _object.localScale.z * 0.5f - _object.right * _object.localScale.x * 0.5f;
		BR = _object.localPosition - _object.forward * _object.localScale.z * 0.5f + _object.right * _object.localScale.x * 0.5f;
	}

 

Now i should check if my player is inside that x and z value. But some plane have a negative value..

4 hours ago, Mirko Rossetti said:

But some plane have a negative value..

it mean that plane have inversed normal. To have a same signum values you have to make all poligons point strictly in CCW (or CW)order that same for each poligon from wich planes built. really its basics of analitical geometry that usually studied on 1-st semester.

#define if(a) if((a) && rand()%100)

22 hours ago, Fulcrum.013 said:

it mean that plane have inversed normal. To have a same signum values you have to make all poligons point strictly in CCW (or CW)order that same for each poligon from wich planes built. really its basics of analitical geometry that usually studied on 1-st semester.

yes i know...i'm sorry for that stupid question, actually i solved it by doing this 


public bool IsBetween(double testValue, double bound1, double bound2)
    {
        return (testValue >= Math.Min(bound1,bound2) && testValue <= Math.Max(bound1,bound2));
    }

 

then, about the position relative to the plane gameobject, i choosed this way


private void SetupPlane()
	{
		_planeRInverse = new Quaternion[planeArray.Length];
		for (int i = 0; i < planeArray.Length; i++)
		{
			_planeRInverse[i] = Quaternion.Inverse(planeArray[i].rotation);
		}
	}	
private void CheckPosition()
	{
		Vector3 playerPos = _pvotPlayer.transform.position;
		Vector3 v1;

		for (int i = 0; i < planeArray.Length; i++)
		{
			v1 = playerPos - planeArray[i].position;
			Vector3 lv1 = _planeRInverse[i] * v1;
			float scaleX = planeArray[i].localScale.x;
            float scaleY = planeArray[i].localScale.z;
            float vh = 5f * scaleX;
            float vf = 5f * scaleZ;
            if ( IsBetween(lv1,0.0f - vh,0.0f + vh) && IsBetween(lv1,0.0f - vf,0.0f + vf)
            {
                //do stuff
            }
		}
	}

with this i was able to detect the exact position of my player inside a plane, now what i should do it's to project the velocity and get if a certain amount of time it will be inside or not, it's just moving forward so it should be easy i think.

You anycase inside a plane on start. so you just can remember plane id and surface coords on it and update it on movements. When object go to other plane jus t remembet other plane id and recalculate surfacee coord respectively to its plane that become to current. In case all planes lie in same plane it required just to shift basis.

#define if(a) if((a) && rand()%100)

On ‎10‎/‎11‎/‎2018 at 12:02 AM, Fulcrum.013 said:

You anycase inside a plane on start. so you just can remember plane id and surface coords on it and update it on movements. When object go to other plane jus t remembet other plane id and recalculate surfacee coord respectively to its plane that become to current. In case all planes lie in same plane it required just to shift basis.

thank's for your advice, i really appreciate it.

actually the problem is that i'm adjusting Y with it, but when i have some kind of downhill i'll get a strange movement like this

 

in black the downhill, in green my character movement, actually he's going top rotate of 15 degrees because i'm setting the rotation of it by the rotation of the actual plane on the x axis.

i can't figure out why it's happening it.

 

Immagine.jpg

1 hour ago, Mirko Rossetti said:

i can't figure out why it's happening it.

Also in case your character have to move along a surface only(i.e. can not jump/fall from borders) you can calculate coords by other way - to move character in current surface u,v coords and then compute a world position substituting current u,v to equation of surface. For planes its very simple to do. Also in case of planar only floor surfaces it  can be easily extended to jumps/falls. You just have to substitute x,y,z of coord of closest to plane point of object to equation of plane to find a distance by normal and then project a 3D velocity to its vector. By other worlds - to add 3-rd dimension to same algo to have a time point on wich jumped/falling object will hit a plane and wich same plane, and ever to advice a coords of hit point. Really floor is same plane as wall but  have other orientation of its normal vector. Only difference betwin walls and floors/ceiling that walls have a zero vertical component of normal, while horizontal floors/ceiling have  a vertical component of normal 1 and other components is 0 for horisontal floor, and much higher vertical then other components for slooped floors. 

#define if(a) if((a) && rand()%100)

This topic is closed to new replies.

Advertisement