简体   繁体   中英

Locking the position of a 2D sprite in Unity2D

I'm trying to lock the position (both x and y) of a sprite in Unity2D. I know that Rigidbody3D has constrain features, but Unity2D only has a "Fixed Angle" option (I'm making gears that mesh together and turn other gears so obviously I still want them to be able to turn). Is there anyway to fix a sprite into place?

Thanks

rigidBody2D.isKinematic=true;

To quote from the unity manual:

The Is Kinematic setting switches off the physical behaviour of the Rigidbody 2D so that it will not react to gravity and collisions. This is typically used to keep an object under non-physical script control most of the time but then switch to physics in a particular situation.

Therefore gravity doesnt affect it, collisions don't affect it. You can still move it using scripts, but it won't move via the physics engine.

Sounds like you may want the 'position-locked' game object to be kinematic. Kinematic rigid bodies cannot be moved by forces.

I'm not sure if this is an option in previous versions of Unity, but Rigidbody2D components come with the 'Is Kinematic' flag without any editor customization. So this can be done without creating scripts.

In Unity 5: Rigidbody2D是运动标志

Unity Rigidbody2D Doc: https://docs.unity3d.com/Manual/class-Rigidbody2D.html

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