Hello Guest

Author Topic: Problem with colliders, sprites, and physics.  (Read 4399 times)

EvilDeathCrab

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Problem with colliders, sprites, and physics.
« on: June 27, 2013, 07:06:11 am »
I'm working on a game prototype where I am trying to create three animated sprites: the player, the enemy and a weapon (an animated sprite that is the child of the player). The enemy is a gameobject of sprites with rigidbodies that will "explode" out of place (ideally using physics) when I kill the enemy.

Right now I am currently having a bear of a time getting all of that to work. My current setup is:

The weapon is an animated sprite that has "create collider" checked. Additionally the sprites making up the sword swing have trimmed box colliders. However whenever the animation plays and the sword swings it is not triggering any OnCollision* or OnTrigger* events.

My Player is a Unity standard Character Controller, the animated sprite is set to not create a collider. If I make my enemy a trigger then my character controller will fire events, but the sword animation will not.

I got frustrated and started arbitrarily adding physics (great debugging, I know) and I was able to get my sword swing to register collision when I:
* Made my capsule regular collision.
* Made my 3 enemy "pieces" all have collision.

When I do this the collision all sort of slams together and my enemy goes flying, but when it lands I can "attack" it with my sword swing and the collision registers. However, the invisible capsule collision of the initial positioning is lingering.

I'm probably rambling a bit too much and showing off how little I know about colliders and Unity, but I'm not sure what I'm doing wrong. Any advice would be appreciated!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem with colliders, sprites, and physics.
« Reply #1 on: June 27, 2013, 11:54:42 am »
If you're moving a collider, you should have a kinematic rigidbody. Do you have one set up on there?

EvilDeathCrab

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Problem with colliders, sprites, and physics.
« Reply #2 on: July 11, 2013, 07:28:00 am »
Sorry I didn't get back in a timely fashion, but this totally did the trick. I feel a little silly, because this seems like an obvious solution that I should have known.

This may be slightly off-topic, but do you know of any good tutorials (2d or otherwise) I could look into for this sort of stuff? I've been busy prototyping and I keep running into brick walls and posting here.

Just picking your brain if there are any good resources you would recommend, especially when dealing with sprite stuff. Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem with colliders, sprites, and physics.
« Reply #3 on: July 11, 2013, 09:28:20 am »
I don't know of any specific 2D tutorials, but the 3D ones by Unity are really worth going through. It may not interest you but you pick up a ton of essential information there.