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 Jdogmaster · Apr 26, 2018 at 03:12 AM · physicspulloncollisionexit

stoping objects oncollision exit

how can i an exit script to this script so instead of stoping objects completely on exit it will like slowly come to a stop rather than instantly? public bool useFixedDirection; public Vector3 pullDirection; public float timescale = 1; public float pullSpeed; public float radius;

  private SphereCollider _col;
  private Vector3 _enterDirection;
 
  private void Start()
  {
      _col = GetComponent<SphereCollider>();
  }
 
  private void Update()
  {
      _col.radius = radius;
      Time.timeScale = timescale;
  }
 
  private void OnTriggerEnter(Collider other)
  {
      _enterDirection = (transform.position - other.transform.position).normalized;
  }
 
  private void OnTriggerStay(Collider other)
  {
      float _dist = Vector3.Distance(other.transform.position, transform.position);
      float _ratio = _dist / radius;
      if (useFixedDirection)
          other.attachedRigidbody.AddForce(pullDirection * pullSpeed * _ratio);
      else
          other.attachedRigidbody.AddForce(_enterDirection * pullSpeed * _ratio);
  }
 
  private void OnTriggerExit(Collider other)
  {
      other.attachedRigidbody.velocity = Vector3.zero;
  }

}

@Kilsnus

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

2 Replies

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

Answer by MarioSantoso · Apr 26, 2018 at 03:39 AM

Simply change the line in OnTriggerExit to

         other.attachedRigidbody.drag = 1;
 

This will increase the drag once it exit the tornado causing it to slow down. And if you have gravity turned on, it will be pulled down also.


As you get more familiar with the codes, I believe you can further improve the simulation, like gradually increasing drag to create the effect you want, etc. Just play around and do experiments with the codes to create a believable simulation.

Comment
Add comment · Show 2 · 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 Jdogmaster · Apr 26, 2018 at 03:55 AM 0
Share

wow! works purfectly how i wanted it to! thanks again man! ya im still kindof a beguinner at scripting. i started unity like 3 months ago and right when i started i started on this tornado project and at first i had no idea what i was doing :D but ive figured it out for the most part i think, and have learned bits and pices of C# scripting along the way. in the summer im going to do a c# class so i can learn it and get better! thanks again man!

avatar image MarioSantoso Jdogmaster · Apr 26, 2018 at 04:33 AM 0
Share

No problem, just shout out when you are stuck again. And good luck with your project and school.

avatar image
0

Answer by himanshugupta159 · Jul 03, 2019 at 05:47 AM

Hi i have written a blog on -How colliders work in unity and how to interact with colliders using script. Pls visit and show some love. Thank you in advance.. link text

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

198 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

Related Questions

Why is my Rigidbody freaking out like this? 0 Answers

How do I make pull object script out of this? 1 Answer

pulling gameobjects across collider C# 3 Answers

Can you use OnCollisionExit with an OverlapSphere? 1 Answer

calcule the distance in addforce. 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