简体   繁体   中英

What is the best way to move an object with the player in Unity C#?

I am trying to get a player pull and push objects in my 3D game. I am mainly focusing on pulling and pushing a box. Now when a player collides with a box and the E key is pressed the isKinematic of the box becomes false, and the player is able to move the box with its own mass.

I am trying to implement a basic pull and push interaction of the object. I have been thinking moving the box along with the movement of the player based on the WASD input but it doesn't sound stable, which road should I take here? Should I use a Fixed Joint connect them? I tried putting the fixed joint the box and making the connected body the player, but now the player is not able to move like there is a collision around it.

What is the best way to implement this? Should I use Fixed Joint or take a different way? Thanks.

if you really want to work with physics, i would say use a rigidbody. Use the rigidbody.AddForce or rigidbody.velocity to move your player. or use the transform by lerping to the position, but this is a bit messy and could not register all of the collisions if you are working on a fast object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM