Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kbrizov · Oct 28, 2020 at 03:21 PM · rigidbodyrigidbody2dkinematicrigidbody.velocityrigidbody physics

Kinematic rigidbody movement.

Hello everyone,

I have this scenario. I have a simple prefab which has the following components:


  1. RigidBody2D - marked as kinematic.


  2. CapsuleCollider2D.


  3. PerceptionComponent - a custom component that uses Physics2D.CircleOverlapAll to detect other instances of the prefab in question.


  4. MovementComponent - a custom component that contains the movement logic.


I read a lot about kinematic rigid bodies and I'm confused. My understanding is that every moving object in my game should either be a dynamic rigid body or kinematic rigid body. This way the objects are registered in the "Physics world" by the Physics engine. Static rigid bodies are optimized by the physics engine.


In my case, I don't want my prefab to collide with anything. I'm using its collider only in the perception component to do a circle sweep in a given radius.


What is the PROPER way to move the prefab (kinematic rigid body)?

  • Should I manipulate transform.position/rotation directly?

  • Should I use RigidBody2D.MovePosition/MoveRotation?

  • Should I manipulate the rigid body's velocity?

  • Should I use FixedUpdate or Update in my case?


The documentation was ambiguous (to me) when it came down to kinematic bodies. I'm looking for the best way to move a kinematic body. What are the differences between the different approaches in terms of the Physics Engine?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lucas_Lima_14 · Oct 28, 2020 at 04:56 PM 0
Share

You can move it with the two ways, my personal preference for kinematic bodies (like space shooter games, for example) is moving it using the rigidbody itself, first getting the input value and changing the velocity using a new Vector, the movement looks more smooth to me, and of course, when dealing with Physics components, using FixedUpdate.

avatar image kbrizov Lucas_Lima_14 · Oct 29, 2020 at 06:42 AM 0
Share

Hello, thanks for the reply. I got the best results when I used transform.position directly, but the question is different. I need to know the details behind the different approaches.

  • transform.position

  • rigidbody.position

  • rigidbody.$$anonymous$$ovePosition

It's important because they are all different to the Physics Engine and without knowing what's going on we might suffer from performance issues.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by kbrizov · Oct 30, 2020 at 03:52 PM

I'm grateful for the opportunity to talk to @MelvMay who was kind enough to answer my many questions. I'm posting his reply here so future readers can benefit as well.


alt text


mvp.png (163.5 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Reid_Taylor · Oct 28, 2020 at 06:25 PM

I believe you should manipulate transform.position/rotation. Because you shouldn't be able to use Rigidbody2D.MovePosition/Rotation when a rigid body is kinematic. Same thing with changing velocity. And When ever dealing with physics you should use fixed update although you could use update if you use transform.position/rotation. Hopefully this answers your question. Anyone feel free to correct me.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kbrizov · Oct 29, 2020 at 06:37 AM 0
Share

Hello, thanks for the reply. The documentation for RigidBody2D says that $$anonymous$$ovePosition is intended to be used with kinematic rigidbodies (check the note near the bottom):

https://docs.unity3d.com/ScriptReference/Rigidbody2D.$$anonymous$$ovePosition.html

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

195 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbody2D adding force vs modifying velocity for character jump 1 Answer

Problem with a RigidBody and IsKinematic... I think 1 Answer

Why does Rigidbody.OnDisable() reset the velocity? 1 Answer

Rigidbody velocity updates on wrong collision Object,[2D] Rigidbody velocity updates on wrong collision object, 0 Answers

VR Sword Physics, how to add force or velocity to the sword for impact when it hits an object 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges