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 /
avatar image
0
Question by rlawnsdudwo · Sep 10, 2019 at 12:37 PM · animationcollision detectionontriggerenterontriggerstay

OnTriggerEnter doesn't work with fast animations/movements

Hello developers! I am super beginner, and I have just started learning Unity recently.

For now, I am trying to simulate melee attacks hitting enemy with mesh collider of the weapon.

The reason I want to use mesh collider is only because i prefer super precise hitboxes.

Also I want to use swinging animation speed for attack speed increase/decrease.

The problem is, if the weapon swings too fast(by increasing animation speed), the frames cannot catch it properly, and it looks like the weapon is going through the enemy and won't trigger OnTriggerEnter (it doesn't happen if animation speed is slow enough).

I tried improved the situation by using OnTriggerStay, however, it is still very unreliable on fast animations.

So, I am looking for the best collision detection tricks for this kind of situation.

Please help! Thank you!

P.S. I have designed animation by hand. So no trigonometric motions are used (and I am bad at trigonometrics haha)

,Hello developers! I am super beginner, and I have just started learning Unity recently.

For now, I am trying to simulate melee attacks hitting enemy with mesh collider of the weapon.

The reason I want to use mesh collider is only because i prefer super precise hitboxes.

Also I want to use swinging animation speed for attack speed increase/decrease.

The problem is, if the weapon swings too fast(by increasing animation speed), the frames cannot catch it properly, and it looks like the weapon is going through the enemy and won't trigger OnTriggerEnter (it doesn't happen if animation speed is slow enough).

I tried improved the situation by using OnTriggerStay, however, it is still very unreliable on fast animations.

So, I am looking for the best collision detection tricks for this kind of situation.

Please help! Thank you!

P.S. I have designed animation by hand. So no trigonometric motions are used (and I am bad at trigonometrics haha)

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
1

Answer by tomc128 · Sep 10, 2019 at 06:04 PM

There's an option in the Rigidbody component called 'Collision Detection'. Changing this to 'Continuous' can improve fast-moving collisions and triggers. This usually solves the problem for me, but they recently introduced two new continuous modes which may also solve the problem. Here's the documentation for the collision detection: https://docs.unity3d.com/ScriptReference/CollisionDetectionMode.html

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
avatar image
0

Answer by ZeBarba · Sep 10, 2019 at 02:08 PM

You should post your code to receive better answers. Your question text is doubled.

Nevertheless, I had this problem once, so I think I can help a little bit. What I could came up with at the time was this:

  • Objects moves are not actually continuous, they "teleport" a little bit each frame, according to its speed.

  • In general, it is enough to detect collisions. If the object is "teleported" inside another object, Unity "pushes" it back outside this object and calls a collision.

  • But if your speed is large enough, it it miss the object and "teleport" to straight to its back, therefore no collisions will be called.

If you REALLY must use this logic, there a method called SweepTest on the Rigidbody object. You must use it to overcome this limitation. The documentation is here: https://docs.unity3d.com/ScriptReference/Rigidbody.SweepTest.html It basically tracks the trajectory of the object and checks if it would have collided with anything on the way.

Please note that the mesh collider is already expensive, and this will make it even more expensive. Maybe you should consider if that high velocity is actually necessary. Or even the mesh collider.

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

284 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

Related Questions

OnTriggerEnter called one step too late 0 Answers

animation and sound aren't playing on trigger 0 Answers

Could some one help me with this script... 5 Answers

Particle System emits on Trigger Stay, in Unity 5 1 Answer

Trigger area around player. 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