Maltakreuz

For some reason 2d collision detection in unity for colliders and triggers is implemented slightly different.
void OnCollisionEnter2D(Collision2D coll)
void OnTriggerEnter2D(Collider2D other)
Collision2D has a clear straightforward way to obtain collision points via Collison.contacts. Unfortunately there is no such easy way to do it for Collider2D.

My first attempt was to modify spine runtimes for unity. The class that generates a unity trigger for bounding box is BoundingBoxFollower. But just switching true to false on line 135 by
(var collider = SkeletonUtility.AddBoundingBoxAsComponent((BoundingBoxAttachment)attachment, gameObject, true))
seems not to be enough. (i just made it following this great video tutorial ). So my questions are:

    1) Is it possible to get the exact contact points for bounding box attachment?
    2) If so, what is the intended way to do it in spine-unity? Should i switch trigger to collider? Or should i use trigger and somehow detect contact points for them via raycast like this.
    3) Is there any alternative solutions for that? Actually i am making a sword hit and want to obtain collision point to determinate a "injured" part (head, body, legs) and a vector for kickback force.
Аватара пользователя
Maltakreuz
  • Сообщения: 43

Pharan

I think the question about triggers vs colliders may be for the Unity forums since that's is barely related to Spine's systems. Probaby people much more knowledgeable about it there.

I mean I guess you could check for collisions yourself with the BoundingBoxAttachments yourself. You'd need to take the polygon intersection code from somewhere else. Otherwise there's really no recommendation for how you "should" do this (whatever you're doing, I guess) in Unity except to either play by Unity's rules/API or do everything manually yourself in C#.

Just offhand though, using colliders means they'll be subject to physics forces and push things around.

Personally, unless it's an actual physics-themed game, I would use all triggers and never use BoundingBoxAttachments and never rely on bone movements for game logic. But that's just me.
Аватара пользователя
Pharan
  • Сообщения: 5366

Maltakreuz

Pharan писал(а):Just offhand though, using colliders means they'll be subject to physics forces and push things around.
Yes, but it's possible to make them kinamatic and push to separate physics layer to interact only with each other. So switching spine runtime on colliders2d instead of triggers will give the contact points out of the box.
Pharan писал(а):I would use all triggers and never use BoundingBoxAttachments.
You probably mean "I would use all triggers and never use colliders". Since BoundingBoxAttachments produce triggers in current spine-runtime.

Actually me too, but anyway i need the exact impact point for trigger to apply "kickback" force on enemy, after a sword hit.
Аватара пользователя
Maltakreuz
  • Сообщения: 43

Pharan

No, I meant I wouldn't define BoundingBoxAttachments in Spine editor, and wouldn't use BoundingBoxFollower. I lean towards the camp that likes to separate animation data from logic data, and I totally understand that that's more purist than helpful in some cases, especially if the animator is the game designer and the programmer anyway so misplaced responsibilities wouldn't be a thing. Though even then, there's still things about the animation being framerate dependent and updated at a different timestep than actual physics and all sorts of unpredictability problems that I don't like (for non-physics-themed games). But again, just me. :p

Let us know if you manage the thing with kinematic rigidbodies though.
Аватара пользователя
Pharan
  • Сообщения: 5366


Вернуться в Unity