I am trying to make a 2d skateboarding game and I need to make the player rotate based on the rotation of the block under neath the player. This way skating down a ramp the board is on the ground
(I am kind of new and this is how I would think of it)
Basically I was thinking of casting a ray or somthing that would detect the platform underneath the player. Then it would then find the rotation of that platform and rotate the player perpendicular to that.
Does anyone know how to find the rotation of an object underneath a player object?
No idea why but for some reason sparkzbarca’s anwser became a comment and now neither I nor anyone else can see the rest of the conversation even if you coment on it.
This is what he wrote as the anwser:
Ray ray = new Ray();
RaycastHit hit;
Vector3 axis;
float angle;
ray.origin = transform.position;
ray.direction = -transform.up;
Physics.Raycast(ray, out hit);
axis = Vector3.Cross(-transform.up,-hit.normal);
if(axis != Vector3.zero)
{
angle = Mathf.Atan2(Vector3.Magnitude(axis), Vector3.Dot(-transform.up,-hit.normal));
transform.RotateAround(axis,angle);
}
it works.
Hello!!
Works perfectly! I would like to know why are we using Vector3.Dot in this case to get the x position?
Thank you!
Thanks so much this is really helpful!