Calc sliding vector...

Started by
2 comments, last by _WeirdCat_ 3 years, 10 months ago

So i began to write collision again, in order to calculate new velocity vector after collision i want to project a vel vector onto plane to get new velocity direction (and length) however i get something else (almost the same direction as initial vel vector but X times bigger length)

So after calcing collision point and collision normal i do:

		pp->pos = nearest_col.new_pos;
		vec3 slide_n = nearest_col.col_normal;

		float slide_d = -dot(slide_n, nearest_col.col_point);
		
		vec3 vprojected = ProjectVectorOnPlane(slide_n, slide_d, pp->vel);
		pp->vel = vprojected;
template <class type> t3dpoint<type>  ProjectVectorOnPlane(
t3dpoint<type> n, type d, t3dpoint<type> v)
{
float signed_dst = dot(n, v) + d;
	
return v - n*signed_dst;
}

INITIAL V: vec3(72.696#-93.9318#111.857) l: 163.156

CALC COLLIDERS

MOVEMENT RAY INTERSECTS POLY

SLIDE N: vec3(-0#1#-0) d: 320

new V: vec3(72.696#-320#111.857) l: 346.694

Now as far as i understand projected vector ahould have x and z components modified and y set to be 0 for this case

And i end up with infinite collision response cause its trying to move almost in the same direction looping forever

Now either project vonplane is wrong or i am missing something…

Advertisement

Seems more complicated then needed, but not sure.

This should work:

vec3 vel (1,2,3);
vec3 planeNormal (0,1,0);
vec3 projectedVel = vel - planeNormal * planeNormal.dot(vel); // should be (1,0,3)

Looks like, it is what i wanted

Hiwever it seems that projected vector length is not dependant on initial vector length

This topic is closed to new replies.

Advertisement