- Home /
Stay on Moving Platform without Character Controller
We are trying to make a character and other objects be able to stay on a moving platform for a 2d sidescroller. The moving platforms have their own tag called moving platform. We tried parenting the objects but they act crazy if the platform rotates or is at an angle. The player does not have a character controller. This is the script we have for the moving platform:
var targetA : GameObject; var targetB : GameObject; var speed : float = 0.1; function FixedUpdate () { var weight = Mathf.Cos(Time.time speed Time.deltaTime 2 Mathf.PI) 0.5 + 0.5; transform.position = targetA.transform.position weight + targetB.transform.position * (1-weight); } function OnCollisionEnter(hit : Collision) { if (hit.transform.tag == "Player") { hit.transform.parent = transform; } }
function OnCollisionExit(hit : Collision) { if (hit.transform.tag == "Player") { hit.transform.parent = null; } }
Answer by Anton Petrov · Dec 16, 2010 at 03:17 PM
If you simply insert one object to another then inserted object inherits all movements and rotations of its parent. Please double check your code.
We would like to avoid parenting because of the problems it causes. We need example code to find out how to solve though.