Is it possible to make animation in Animator (unity), where “object A” will move to “object B”, and put into script only onCollideEnter something? for example on collide, make debug.log(“blabla”);
Because i need make a few animations of spells for my game, and i think about make them by animator (cuz it’s easier) and make this on Collide enter by script C#, but i’m not sure about this possibility.
So you want the collision events, but these colliders are being animated.
So lets go here:
And look at the graph at the bottom for collision.
Column 1:
As you can see a static collider only receives messages from something w/ a non-kinematic rigidbody attached. Problem here is that moving static colliders is expensive, you shouldn’t ever be animating/moving static colliders… they’re called static for a reason.
Column 2:
A non-kinematic rigidbody receives messages from everything. May it be a static collider, another non-kinematic rigidbody, or a kinematic rigidbody. Probelm here is that a non-kinematic rigidbody is for rigidbodies that are moved using physics.
Column 3:
A kinematic rigidbody, like the static collider, receives messages only from non-kinematic rigidbodies. A non-kinematic rigidbody is for rigidbodies that don’t move by physics, but instead are animated.
This last option is what you want.
Downside is that it only receives messages from a Rigidbody that it will only react if the thing it is hitting is non-kinematic.
Thing is, in your post, you mention needing to know when your spell hits something. This sounds like you’re talking about an ‘Area of Effect’ spell. This doesn’t really need collision, this needs just intersection tests (collision implies force, physics).
You can set the collider as a trigger, and see if it intersects another collider. As you can see in the second graph (for triggers), a kinematic rigidbody with trigger colliders receives the trigger messages (OnTriggerEnter, OnTriggerExit, OnTriggerStay) no matter what the collider is.
This is the option I always go with when dealing with hitboxes.
ok working perfect, i gave Box Collider 2D for the animated object and mark Is Trigger + gave tag “testTAG”,
added Box Collider2D and Rigibibody 2D for my Object, and working perfect! Thanks again