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 Excludos · Jun 26, 2018 at 08:35 AM · collisionvelocity

collision.relativeVelocity always zero

I'm having trouble getting relativeVelocity to show anything other than zero. The setup is somewhat simple:

The object with the rigidbody (the player) is standing still while the world moves around it. It has a Box collider which is bolted onto one of its child objects.

The object it is crashing with is travelling around a globe using transform.RotateAround, and also uses a Box collider (It does not have a rigidbody).

You'd think this would be a relatively simple setup, yet when they crash together, it triggers a collision like it should, but the relativeVelocity is always (0.0, 0.0, 0.0) (collision script is on the player root object).

Any ideas about what I'm doing wrong? Is this because I'm controlling the objects with transform instead of accelerating the rigidbody? Is there something else I could be using instead to find collision force if relativeVelocity is the wrong solution?

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
1
Best Answer

Answer by tormentoarmagedoom · Jun 26, 2018 at 08:42 AM

Good day.

Rigidbody component is the Physics compoenent, so relativeVelocity is between 2 objects will give you results if both objects have rigidbody.

If the player i colliding with a inmobile objecto, you only need to see the velocity of the polayer (the other is 0) .

But if you need to know it from 2 moving objects, you need to add Rigidbody to both objects.


Extension:

Mmm... I must say i never used it ,so i can not talk with experience...

Aaaaand if you get the 2 Vector3 velocity and calculate the relative via Mathematics??

Why you need toknow the relative? Is to calculate the "force" of the impact? Then do something like this:

 Vector3 ImpactVector = Object1.velocity - Object2.velocity;
 float ImpactForce = ImpactVector.magnitude;

So you have now a flaot number from the impact force.

Bye!

Comment
Add comment · Show 5 · 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 Excludos · Jun 26, 2018 at 08:57 AM 0
Share

Thank you. However I am still receiving 0 in relative velocity even if both objects have rigidbodies.

avatar image tormentoarmagedoom Excludos · Jun 26, 2018 at 09:12 AM 0
Share

Extended answer :D

(PD: Always, when you get a working answer, accept it to help other users find the good solution)

avatar image Excludos · Jun 26, 2018 at 09:29 AM 0
Share

The reason the relativeVelocity would have been nice is because I want to know the direction of the impact. I would like a head on impact (in the x direction) to be immediately lethal, while a sideways impact (in the z direction) should maybe only slow the player down (Think a arcade style car touching the guard rails as opposed to crashing headfirst into a wall).

I see my issue is that neither object have a measurable velocity because I'm putting constraints on them (otherwise they just fly all over the place). Therefore I will need to find another solution. However my original question has been answered, so thank you for that.

avatar image tormentoarmagedoom Excludos · Jun 27, 2018 at 03:43 PM 0
Share

IF you store the position of an object and store it again few moments after, you can create a vector that is the real direction of the object

avatar image Excludos tormentoarmagedoom · Jun 28, 2018 at 07:42 AM 0
Share

The way I ended up doing it was to draw a vector from object to collision point and simply see if the direction of impact is beyond a certain value.

It's not the best solution, as it won't let me do things like variable damage depending on force of impact and such, but it's good enough for the moment.

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

How to add rigid body forces and collision detection to SimpleCameraController 2 Answers

bouncy between two objects with velocity 0 Answers

How to calculate velocity after collision? 0 Answers

Stuck on using if else to prevent ball from getting stuck in brick breaker. very new to unity & C# :(,How would I reference an object to add onto its velocity in 2D? 1 Answer

Bounce, gravity and velocity 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