• 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.

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

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

Can you use OnCollisionExit with an OverlapSphere? 1 Answer

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

How to I access different collider on the same parent class 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges