Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by kpetkov · May 23, 2018 at 01:18 PM · physicsrigidbody2dcollision detectioncollider2dmovinggameobject

How to stop game object movement instantly after collision is detected ?

Hi, I have a moving object with some colliders and rigid body attached to it. The colliders used are box and polygon, I use box colliders to identify a part of the moving object as head/leg and polygon for identifying body.All happens in Unity 2018.1.0f2 and working on 2D I also use box colliders for identifying some elements as destroyer (it destroys any moving object colliding with) and bottom (certain moving objects can step on it and certain can't). All static objects (bottom and destroyer) dont have rigidbodies attached. Moving objects rigidbodies are Type: Kinematic, Simulated: true, Use Full kinematic contacts : true, Collision detection : continuous Sleeping mode: start awake, Interpolate: none Using OnCollisionEnter2D for checking collisions between the objects. The script for collisions is attached to every moving object and disabled after certain action happens. Another script is using for controlling moving objects movement. and Inside public Vector2 velocity = new Vector2 (0f, -32f); void FixedUpdate () { rb2D.MovePosition (rb2D.position + velocity * Time.fixedDeltaTime); } void Update () { velocity = Input.GetKey (KeyCode.DownArrow) ? new Vector2 (0f, Mathf.Clamp (velocity.y - 32, -224f, -32f)) : new Vector2 (0f, -32f); } Local variable Velocity inside Update method is used for controlling speed of movement, and Global Velocity is used as some controllable constant. In script with cellision detections there is a method private void StopRigidBodyMovement () { moveScript.enabled = false; rb2D.bodyType = RigidbodyType2D.Static; } That is used for stopping rigid body movement, when making it static and prevent further movment disabling the script responsible for moving object. BUT! The problem is that moving object stops after a while and not immediately as expected. And As the question says: How can I immediately stop figure movement after collision happens ?

Comment
Add comment
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

1 Reply

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

Answer by kpetkov · May 25, 2018 at 09:08 AM

As the mainual states Physics events like collisions and interactions with other objects works well ONLY FOR DINAMYC TYPE RigidBoby! So to stop RigidBody at the exact moment it has to be dynamic. One possible solution is to use RigidBodyConstraints https://docs.unity3d.com/ScriptReference/RigidbodyConstraints.html, also if rb2D is the RigidBody use rb2D.velocity = Vector2.zero; rb2D.angularVelocity = 0f;

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

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

203 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Object Colliding while passing along another object . 0 Answers

My player ¿Collider? is too big 0 Answers

Unable to stop animation upon collision (2d, animation, rigidbody) 0 Answers

Rigidbody projectile misses collider 1 Answer

Projectile Changing Angle BEFORE Impact 0 Answers


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