- Home /
How can I change the other objects velocity when using OnTriggerEnter2D?
I want to make my Player to stop after a short delay when entering a zone
Comment
Answer by hatenames · Jul 20, 2016 at 02:18 PM
rb.angularVelocity = Vector3.zero;
rb.velocity = Vector3.zero;
float time = Time.time + 1;
where rb is your Rigidbody. of course to set the delay you have to create a float that takes in the current time and add to it, then do a check for Time.time > time to stop.
Answer by NoseKills · Jul 20, 2016 at 04:01 PM
void OnTriggerEnter2D(Collider2D other) {
StartCoroutine(StopAfterDelay(1, other.gameObject.GetComponent<Rigidbody2D>()));
}
IEnumerator StopAfterDelay(float delay, Rigidbody2D body) {
yield return new WaitForSeconds(delay);
body.velocity = Vector2.zero;
}
Wrote it on my phone so sorry if there's spelling errors. Should give you an idea anyways.
Your answer
Follow this Question
Related Questions
Will it work? Need help! 3 Answers
Version not compatibile 0 Answers
UI resolution issues - Build EXE 5 Answers
Multitouch on Windows 7? 7 Answers
win7 64 bit - horrible perf? 4 Answers