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 HeartOfGermany · Mar 15, 2020 at 12:01 PM · physicsgravityspin

Move asteroid realistically in 0 Gravity from hit (impact plus pressure wave)

Heeeelllooo! <3

I found a way, to actually move away an asteroid, when hit by a bullet. It always goes into the opposite direction of the laser(bullet) that hit it. However this is quite unrealistic. If I hit it on its left side, it should go to the right and also pic up some rotation. The bullet uses a capsule collider, the asteroid is polygon collider.

I use this script:

     private void OnTriggerEnter2D(Collider2D collisionData)
     {
 
       
          var magnitude = -25;    // How much to moove asteroid? Negative = Away from laser/player
  
          var force = transform.position - collisionData.transform.position;  
  
          force.Normalize ();
          GetComponent<Rigidbody2D> ().AddForce (-force * magnitude);



Of course this script ony creates a linear direction. Let me explain, what I mean:

I want to detect the angle at which the bullet collides with the polygon collider. If I got a complex asteroid shape, this is required to react in a realistic manner. Say it is an "S" shape and I hit it at its tail on the inside. It basically hits on the edge, but the force still should not go to the center, rather outwards, since it still hit inside. Also it should - depending on the angle between 1) the laser and 2) the line between center and the hitpoint - create some rotation. In space this would happen.

So how do I extract the angle, of wich it collided with and use it do determine the rotational force applied?

In less than 20 words: - Laser hit creates presure wave - Laser hits with kinetic force How do move asteroid realistically?

Thanks for your help.

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 JPhilipp · Mar 15, 2020 at 03:04 PM 1
Share

@HeartOfGermany Does this StackOverflow answer help?

avatar image HeartOfGermany JPhilipp · Mar 16, 2020 at 06:14 PM 0
Share

@JPhilipp Unfortunately it doesn't. I am searching for a realistic way to archive this. Explosion force also creates rotation on any object, that is not a perfect circle (globe). That means, a linear force is unrealistic. It also needs to spin at a given speed. This depends on the angle of the surface. But to actually get the angle of the surface, I need to use a Raycast (multiple, to be precise). Doing some semi-basic math, this results in some angles and lines of given length.

This is my plan:

-Bullet hits asteroid. -impact.position // how do I get it on 2 trigger colliders? Regular collider can NOT be used for this case -from midpoint to impact position get a vector (basically direction) and add 1 distance = raycast.start.position -from raycast.start.pos (ammount not decided yet) raycast in 15° steps, to get the surface details -get the distance from each ray to the hit object - total.force gets divided by raycasts_ammount (360/15=24) and than divided by distance (get a vector out of this, where the length represents the strength) - combine the vectors to get the precise direction of force and the precise strength - get the angle between the line representing given vector (starting from impact.position) and the angle between impact.position and asteroid.midpoint. - 180° angle means all force converted to linear force - 90° angle means all force converted to rotation - everything in between is possible

Yeah, this is not perfect, but actually relatively close to reality in many ways.

0 Replies

· Add your reply
  • Sort: 

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

286 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 make physics for rail trolley with gravity changing. Unity 2d game 0 Answers

Gravity slow descent after jump 0 Answers

Character not jumping smoothly using CharacterController 0 Answers

Order of execution: AddForce, rigidbody movement, velocity update? 0 Answers

Character only falls when button is pushed down 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