Hello Guest

Author Topic: Sprites do not colliding, Animated Sprites do  (Read 6399 times)

sfbaystudios

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 40
    • View Profile
Sprites do not colliding, Animated Sprites do
« on: December 29, 2012, 06:53:36 am »
Hello!

I have a bunch of sprites (pickups / map tiles) that have box colliders (player doesn't fall through).

I have animated sprites (player, enemies).

I have a "bullet" that when shot will go through sprites but will hit (and destroy on hit, as I've programmed it) when colliding with an animated sprite (enemy).  So it shoots through walls etc.



This may be similar to the problem I had (did not post about) regarding sprites used for touch-movement-controls -- in that case, the box-collider from the Toolkit app didn't allow for clicks/touches.  Replacing the collider with a box collider from the Components menu suddenly allowed the sprites to be clicked/touched.


Is there some reason why the sprites are not seeing collisions while the animated sprites are?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprites do not colliding, Animated Sprites do
« Reply #1 on: December 29, 2012, 06:17:46 pm »
Impossible to say exactly why without actually seeing it in the editor, but...

1. Are you moving the sprites with colliders? If so, do you have a rigid body with kinematic set on them?
2. What kind of collider on the bullet? Box?
3. Are the boxes & animated sprites intersecting on z? They would need to overlap somewhat to actually collide.
4. How do you move the bullet?

There is no difference between the box collider in the toolkit & a normal box collider from them menu, except the default values. Comparing them should tell you why one is working and the other isnt. Perhaps something to do with the thickness (too thick that it is intersecting the camera...)

sfbaystudios

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Sprites do not colliding, Animated Sprites do
« Reply #2 on: December 29, 2012, 09:51:35 pm »
Well, for the buttons I'm using (for touch input), mesh colliders don't show a z-axis option.  Is Trigger/Convex/Smooth Sphere Collisions are all unchecked, no material and mesh is the default.

For the bullet, there's a box collider, and the zsize is not touching the camera, and is wide enough to collide with any/all objects (it hits enemies properly).  I've added a rigidbody/kinematic to the bullet, but it does not change the reaction.  (going step by step, the collider on the bullet does cross the collider on the ground).

1.  Yes, the sprites/colliders are moving together.  I do not have a rigidbody on the sprite, as it didn't change anything.  (I do now, no change).  (Adding one on the ground sprite that the bullet first hits does nothing as well)

2.  Box colliders on both.

3.  Yes, they are intersecting.

4.  The bullet is moved with it's own script:  transform.position.x += (1000 * Time.deltaTime)




unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprites do not colliding, Animated Sprites do
« Reply #3 on: December 31, 2012, 06:21:30 am »
Hard to tell what could cause this. It should collide. I would test with non tk2d primitives of the same type. If you can reproduce, I'd send a bug report to Unity. tk2d doesn't do anything "special" with the sprite colliders, all it does is create them for you.

sfbaystudios

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Sprites do not colliding, Animated Sprites do
« Reply #4 on: December 31, 2012, 10:31:58 pm »
It's more likely that I"m doing something wrong :)

Can I ask a more basic question, since either way I'm just writing logic code right now and will be re-building whatever sprites/maps I've set up:

For a game like old NES 2d side scrollers, what kind of collider settings should be for the following:

* Player
* Enemies
* Ground/wall (assuming bullets are able to collide and be destroyed by them)
* Pickup items (assuming bullets can go through them, although they can still be collided by the player for pickup)
* Bullets (right now my bullets sometimes push back on my player, so I'm guessing I need to turn off the collider, but I'm not 100% sure how to manage the hit on other object?)

Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprites do not colliding, Animated Sprites do
« Reply #5 on: January 01, 2013, 07:44:55 am »
The collider settings can be anything really. The only thing you need to worry about are moving objects. They should be kinematic, or just use Unity physics to move them (AddForce, etc).

For bullets going through objects, etc, you can use layers and the layer mask to say a certain layer won't collide with another. For example, create one called Bullet & another called Pickup, and untick the mask grid for Bullet-Pickup.

The other alternative is to roll your own solution using Unity Raycasts to do everything.

sfbaystudios

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Sprites do not colliding, Animated Sprites do
« Reply #6 on: January 01, 2013, 10:45:32 pm »
Having a rigidbody on the bullet works if it is not set to kinematic.