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
1
Question by JadeTheFlame · Dec 03, 2015 at 08:40 AM · instantiatetriggeraiphysics2dcollider2d

Collision with instantiated non-moving objects.

Alright. Hope it's not a tough one. In my game (2D Platformer), there are melee weapons and ranged weapons. Ranged projectiles collisions and triggers work fine. But I can only get non-trigger melee instances to register a hit with the target instance, if the target is moving into it. In other words, if I spawn the melee hitbox on the npc while it is not doing an attack animation, a trigger enter, exit, nor stay will be called until the game object starts moving. additionally, I have tried to animate the projectile to slightly move passively to solve this, but to no avail.

I feel like a previous version of unity did not do this, because i remember having simple target objects instead of AI that i could simply hit with both melee and ranged attacks and they would show a destructive animation. This was all previously to test simple collisions. I loaded up an old backup where this was possible, and now it no longer works with the current version of unity (5.2.3).

Another thing is, I could ofcourse just turn this trigger into a non-trigger collider, and that makes things simpler for the script to recognize because the colliders just push the npc around, forcing movement for the calls. But I want a trigger. I want to code in specific instructions on hit. Like what if I don't want this knockback effect? I can't do that if it throws the enemy due to physics updates from a non-trigger collider.

Any help?

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

1 Reply

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

Answer by wibble82 · Dec 03, 2015 at 10:03 AM

Hi Jade. I've hit this same problem before (both on 4 and 5), and it occurs because the trigger system operates by detecting when objects start/stop penetrating. When you spawn an object penetrating it doesn't seem to trigger, presumably because the rigid body never 'entered' the trigger.

However I believe I fixed it by calling 'RigidBody.MovePosition' on the spawned object and passing it its current position, as this makes the physics engine wake up and see a rigid body that might be doing something. Give that a try anyway - it worked for me a while back.

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 JadeTheFlame · Dec 05, 2015 at 03:55 AM 0
Share

I would accept this answer for its simplistic solution. The problem however, is that collision detection can occur regardless of rigidbodys existing on a gameobject. So I would not say that they are called exclusively related to the rigidbody.

EDIT: On further testing, it is apparently called multiple times, including the calls for rigidbody component collisioned objects as well. The simple solution is to add a rigidbody and set the gravity scale to zero, and continue to set the position through abstract methods if need be, rather than by force values. If you could include some information in the answer I will accept. Thank you =D

avatar image DreamingSpirit · Jul 05, 2016 at 09:11 AM 0
Share

Adding a rigidbody to the instantiated object worked for me.

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

46 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

Related Questions

How to make a collider be is trigger to some certain layers but be normal to others? 2 Answers

How to make a trigger still collides with specifc object? ,How to make a trigger stillcollide with specific objects? 1 Answer

Moving many 2D triggers is slow. Why? 1 Answer

Update scaling and 2d collider/trigger not firing 1 Answer

Ignore collision before instantiating 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