• 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 siddharth3322 · Jan 20, 2019 at 04:20 PM · collisionphysicsrigidbody3dcollision detection

Always Get Same Physics Collision Rebound Force

I was working on a 3d car war game, and I was moving my cars through velocity using the following code:

 appliedSpeed += Time.fixedDeltaTime * 8f;
 appliedSpeed = Mathf.Min (appliedSpeed, speed);
 myRigidbody.velocity = transform.forward * appliedSpeed;

At collision time, I was giving backward force using the following code:

 private void ApplyReboundForce (Collision other)
     {
         Vector3 reboundDirection = other.contacts [0].point - transform.position;
         reboundDirection = -reboundDirection.normalized;
 //        myRigidbody.AddForce (reboundDirection * 7f, ForceMode.Impulse);
         myRigidbody.AddForce (reboundDirection * 180f, ForceMode.Force);
     }

But at present, I was getting a collision response force dynamically. Sometimes it was a higher force and sometimes it was lower force based on physics calculation. I want collision response force always same.

Here is the reference game for collision response force:
SUPER ADDICTIVE NEW .io Game | Bumper.io

I have already made all physics property of all cars same like physics material, rigidbody properties values etc... then also getting different collision response on each collision.

Please give me some suggestion to achieve something similar.

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

Answer by xxmariofer · Jan 20, 2019 at 08:08 PM

Your code seems fine, can you try some things? When are you applying the force on collidion enter or on collision stay since that may be incrementing the applied force. Also i would suggest setting the rigidbody velocity to 0 just before you give the rigidbody the force, that will make the forces (if they all have same properties) the same.

  private void ApplyReboundForce (Collision other)
  {
      Vector3 reboundDirection = other.contacts [0].point - transform.position;
      reboundDirection = -reboundDirection.normalized;
      myRigidbody.velocity = Vector3.zero;
      myRigidbody.AddForce (reboundDirection * 180f, ForceMode.Force);
  }
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 siddharth3322 · Jan 21, 2019 at 04:39 PM 0
Share

$$anonymous$$aking rigidbody velocity didn't work for me. I was applying rebound force like this way:

     void OnCollisionEnter (Collision other)
     {
         if (other.gameObject.CompareTag (GameConstants.TAG_ENE$$anonymous$$Y) || other.gameObject.CompareTag (GameConstants.TAG_PLAYER)) {
 //            myRigidbody.velocity = -transform.forward * appliedSpeed;
             //appliedSpeed = speed * 0.5f;
             elapsedEngineStartWaiting = 0f;
             ApplyReboundForce (other);
 
             if (other.transform == targetPlayer)
                 AssignTargetPlayer ();
 
             lastCollidedEnemy = other.transform;
         }
     }
 
     private void ApplyReboundForce (Collision other)
     {
         //myRigidbody.velocity = Vector3.zero;
         Vector3 reboundDirection = Vector3.Normalize(transform.position - other.transform.position);
         reboundDirection.y = 0f;
 
         //Vector3 reboundDirection = other.contacts [0].point - transform.position;
         //reboundDirection = -reboundDirection.normalized;
         //myRigidbody.AddForce (reboundDirection * 5f, Force$$anonymous$$ode.Impulse);
         myRigidbody.AddForce (reboundDirection * 180f, Force$$anonymous$$ode.Force);
     }

For more information please read this post that I have created: Always Get Same Physics Collision Rebound Force

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

OnCollisionEnter isnt called when player lands on object 1 Answer

How can I make my character after hitting a wall? 1 Answer

Player getting stuck in ground (3D) player has Rigidbody, and Box Collider, world is Mesh Colliders 0 Answers

Player getting stuck in corners 0 Answers

How to Have Two Child Objects of One Parent Detect Collisions Between Eachother. 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