Preserving the players rotation on rotating platforms
Hey guyz
at the moment i am trying to get my moving and rotating platforms going and i kinda have problems with the rotating one.
The rotating of the platform itself works fine but i have problems with my player on the platform. To keep the player moving with the platform so that he stays on it, i followed some advices from here and added a trigger to the platform with the following script:
void Update()
{
Player.transform.rotation = currentrotation;
}
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == ("Player"))
{
col.transform.parent = gameObject.transform;
currentrotation =
Player.transform.rotation * Quaternion.Inverse(Platform.transform.rotation);
}
}
void OnTriggerExit(Collider col)
{
if (col.gameObject.tag == ("Player"))
{
col.transform.parent = null;
currentrotation = Player.transform.rotation * Platform.transform.rotation;
}
}
I'm parenting the player on the moving platform to preserve the motion.But as soon as the platform is rotated i have the problem that the player gets the rotation from the parent added, which results in a jerky rotation of the camera. Here is a short video of that:
That is why i added the part with currentrotation. My idea was basicially that as soon as i enter the trigger i am substracting the rotation of the platform from the player to make it normal again, but that obviously didn't work and i currently have no idea how to get that to work. Would be great if someone could help me out!
PS: I am kinda new to unity and programming stuff and just started 2 months ago so it would be great if you could explain it noob friendly if you have an idea ;P