• 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 Wenon · May 06, 2018 at 05:14 PM · rigidbodyvelocitymagnitude

Make rigidbody slower not stop after hit kinematic rigidbody

I placed props on my map and they are kinematic and they have script that if car will hit them than kinematic is false. But car on hit stops. How to make only slow down? You know, when car with 999 km/h will hit trash can, car can't stop.

Comment
Add comment · Show 6
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 Eno-Khaon · May 06, 2018 at 05:17 PM 0
Share

Rather than setting them as kinematic, would it be reasonable to put them to sleep when the scene starts ins$$anonymous$$d?

avatar image Wenon Eno-Khaon · May 06, 2018 at 05:33 PM 0
Share

On instantiate objects falls even with sleep() on start/awake. And there would be problem when something will hit prop and I don't want to it fall, like when player will touch lamp.

Show more comments
avatar image hexagonius · May 07, 2018 at 06:39 AM 0
Share

keep track of the cars speed (velocity) and when it collides with the can reapply a reduced amount of it then.

avatar image Yuvii hexagonius · May 07, 2018 at 06:43 AM 0
Share

just like hexagonius said. Put the velocity when the car hits something into a vector3, and then apply a reduced version of this velocity.

 if(*car collides*){
     new Vector3 VelocityWhenHit = car.velocity;
     car.Velocity = VelocityWhenHit / 5;
 }
Show more comments

1 Reply

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

Answer by Eno-Khaon · May 07, 2018 at 11:36 PM

One approach you can try taking to handle this is to essentially do what you've been doing, treating the objects as kinematic until hit. When the collision occurs, you can determine whether the hit should make an object "break free" (A light pole, for example, would be tough to break through, while a trash can would be trivial).

If it doesn't, you don't need to take any action. The stationary object won.

If it does "break free" then re-apply the collision force to the incoming object (car).

My example script in full:

 // C#
 using UnityEngine;
 
 [RequireComponent(typeof(Rigidbody))]
 public class MovableObject : MonoBehaviour
 {
     public float breakingForce = 10.0f;
 
     private Rigidbody rb;
 
     void Start()
     {
         rb = GetComponent<Rigidbody>();
         rb.isKinematic = true;
     }
 
     private void OnCollisionEnter(Collision collision)
     {
         Rigidbody other = collision.rigidbody;
         if(other != null)
         {
             float collisionForce = Vector3.Dot(collision.relativeVelocity, collision.contacts[0].normal) * other.mass;
             if(collisionForce > breakingForce)
             {
                 rb.isKinematic = false;
                 other.velocity = collision.relativeVelocity;
             }
         }
     }
 }


Essentially, the idea is to still let the physics handle a majority of the work, while trying to keep things under control. By extension, this also ensures that an object affixed to the ground won't spontaneously try to move upon colliding with the ground itself, by requiring enough force to enable it to move and taking mass into account for all other physics-based portions of the process.

A car generally weighs a lot, for example, so it would need less speed when impacting a resistant object to break it free. A baseball thrown at 100mph, by contrast, could be moving faster, but wouldn't provide as much force, even when compared with a glancing hit from the car.

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 Wenon · May 10, 2018 at 01:15 PM 0
Share

relativeVelocity was the key, thank you and I forgot about the mass, thanks for the hint and example

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

111 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

Related Questions

void OnCollisionEnter(Collider other) { if (Rigidbody.velocity.magnitude > 5) {...} - In "Rigidbody.velocity.magnitude" asks to give link to the object??? 2 Answers

Why is this loop infinite? 1 Answer

Adding player velocity to projectile not working 0 Answers

Rigidbody magnitude 3 Answers

checking angular magnitude 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