Collisions not working correctly
by Matthew Shapiro · in Torque X 2D · 10/01/2007 (3:52 am) · 6 replies
I'm at a loss at what is going on. So far in my game I have a player ship, enemy ships, and multiple projectiles which shoot out of my ships (with collision which makes my projectiles destroy enemy ships only). I am now in the process of adding powerups which change which projectil fires out of your ship.
Everything works, except getting the powerup to process the collision correctly. What happens is I have the powerup template setup to collidewith my player object and to use my onCollision delegate. I also have ProcessCollisionsAtRest (since it's not necessary for powerups to move around the map.
My collision delegate looks like this:
What happens is that even though collision is enabled for the player ship, it never once calls the delegate (I know cause I put a breakpoint at the ShipMovementComponent line).
Now what gets wierder is I was confused and while thikning about the problem I was randomly shooting around accidentally hit the powerup icon with my projectile. Next thing I know I'm at the breakpoint (which of course doesn't do much since the projectiles do not have the movement component). Both of my projectiles are colliding with the powerup instead of my player template. Both projectiles do not have any objecttype set, and both are set to only collide with my npcEnemy type when fired.
Finally last thing I tried was to set my player ship to collide with the powerup object, and that accomplished nothing. After sitting there running through the object multiple times I then found out that my enemy objects are colliding with it as well. These enemies are set to the type npcEnemy and have everything in the T2DCollisionComponent set to off. All objects are on the same layer btw.
Can anyone give me any insight why everything BUT my player ship is colliding with my object? This doesn't make sense to me.
Everything works, except getting the powerup to process the collision correctly. What happens is I have the powerup template setup to collidewith my player object and to use my onCollision delegate. I also have ProcessCollisionsAtRest (since it's not necessary for powerups to move around the map.
My collision delegate looks like this:
public static void ProjectilePowerupCollision(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info,
ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial)
{
// Make sure the object colliding with us is a player. Only player objects should have this component
ShipMovementComponent obj = theirObject.Components.FindComponent<ShipMovementComponent>();
if (obj != null)
{
// Set the player's fire component to use the new projectile
ShipFireComponent fire = theirObject.Components.FindComponent<ShipFireComponent>();
ProjectilePowerupComponent projectile = ourObject.Components.FindComponent<ProjectilePowerupComponent>();
if (fire != null && projectile != null)
fire.CurrentProjectile = projectile._powerupProjectile;
ourObject.MarkForDelete = true;
}
}What happens is that even though collision is enabled for the player ship, it never once calls the delegate (I know cause I put a breakpoint at the ShipMovementComponent line).
Now what gets wierder is I was confused and while thikning about the problem I was randomly shooting around accidentally hit the powerup icon with my projectile. Next thing I know I'm at the breakpoint (which of course doesn't do much since the projectiles do not have the movement component). Both of my projectiles are colliding with the powerup instead of my player template. Both projectiles do not have any objecttype set, and both are set to only collide with my npcEnemy type when fired.
Finally last thing I tried was to set my player ship to collide with the powerup object, and that accomplished nothing. After sitting there running through the object multiple times I then found out that my enemy objects are colliding with it as well. These enemies are set to the type npcEnemy and have everything in the T2DCollisionComponent set to off. All objects are on the same layer btw.
Can anyone give me any insight why everything BUT my player ship is colliding with my object? This doesn't make sense to me.
#2
and from your power up:
You'll need to set your PowerUps to actually be of ObjectType "powerup" for collision to process correctly.
10/02/2007 (12:09 am)
From your player:<CollidesWith>
<object objTypeRef="powerup" />
</CollidesWith>and from your power up:
<ObjectType>
<object objTypeRef="t2dSpriteType" />
</ObjectType>You'll need to set your PowerUps to actually be of ObjectType "powerup" for collision to process correctly.
#3
10/02/2007 (12:45 am)
Doesn't help. I tried that before and it didn't make collisions between the two happen.
#5
10/02/2007 (1:52 am)
Nothing, they still don't collide (but it stil collides with enemies and projectiles) :(
#6
10/02/2007 (5:58 am)
Ugh ignore me. I somehow must have clicked off Collision Enabled for the lpayer ship. I could have sworn I checked it who knows. Sorry for the trouble.
Torque Owner Josh Butterworth