- Home /
 
Make a game object "carry" other
I had starting to make a platformer, right now with placeholders.
I need that a platform in movement to carry the player. The platform moves via Update method, changing the x transform.
When the player drop over the platform stops but not carry the player.

I tried to make it via animation (with this and kinematic works, but I had problems setting the animation on different places), via super friccion on the material, and so.
Please help!
Update: Now acting on the rigidbody on Fixed update... same result, my code:
 void Start () {
     rb = gameObject.GetComponent<Rigidbody>();
 }
 void FixedUpdate () {
     Vector3 addV = new Vector3(direction * speed * Time.deltaTime, 0f, 0f);
     rb.position += addV;
     if (rb.position.x > maxRight || rb.position.x < maxLeft) direction *= -1;
 }
 
              How about making player child of the platform when they collide?
Answer by Chimer0s · Feb 08, 2019 at 10:32 AM
You'll want to move the platform with velocity/forces applied to the rigidbody in fixed update. Moving it by its transform (especially in update) will not correctly perform any physics calculations. You may also want to create a phsyics material that you can apply to the colliders of the player and the platform with higher friction values.
Thanks for the answer but... same result. I have put my modified code on the answer.
Your code is still setting the position, not applying a force. You could try something like rb.velocity = direction * speed; This will move it with physics, not by setting its position.
Edit: Accidentally added Time.deltaTime to the equation. It isn't necessary when dealing with velocities.
Oh yes... finally I did:
 rb.AddForce(new Vector3(direction * speed * Time.deltaTime, 0f, 0f));
 
                    It works! thanks a lot.
Your answer