I added a cube, which is continuously moving back and forth in the z direction, using a simple sinus formula.
When I jump on the cube with my first person controller, the cube keeps moving, but the player doesn’t move along; it stands still, which is not a natural result.
How can I achieve the player to ‘be carried by the cube and thus moves along’?
With a CharacterController, the platform’s motion won’t be passed on to the player. You need to move the player by the same amount that the platform is moving. A object with rigidbody physics will be carried along by a moving platform, but a rigidbody object is often not suitable for an FPS player character.
I came to the forum looking for the same answer. But later on i figured it from myself so here it is:
You create an Empty Object with a Box collider over the cube (flying platform) and you make it child to your moving platform, then you create this script for the Empty Object
function OnTriggerEnter (other : Collider) {
// Get the transform of the camera
var cameraTransform = Camera.main.transform;
// make it a child of the current object
cameraTransform.parent = transform;
}
function OnTriggerExit (other : Collider) {
// Detaches the transform from its parent.
other.transform.parent = null;
}
You need to activate the Trigger option in the box collider
What we are doing here is that when a collider object (in this case our camera with the character controller) this object will be the child of the Empty object as long as it is over it