Early out alternative?
by Cosmic Logic · in Torque X 2D · 11/23/2009 (6:55 pm) · 1 replies
Hey,
I'm playing with early out collision stuff right now.
The problem I'm trying to solve is that when I have my ball flying around I only want it to collide sometimes with players and sometimes not.
Early out collisions have half the problem solved, the ball won't collide with a player from the opposite team if the shot type is a pass.
The actual shooting is the problem. My end goal is to have a chance to intercept, a chance to miss entirely (no collision) and a chance to block and deflect the ball.
The deflect and block work fine in the collision delegate, but the pass through doesn't work so well. If I put the pass through chance in the early out test it makes a check 30-40+ times on the way and through that player. So something I only want to happen once (to give fair odds with the other two options) happens 30-40 times. If I put the pass through in the collision delegate, the physics engine gets a crack at it before my delegate, so I can get it to pass through (with a CollisionsEnabled = false for 150 ms on a schedule) but it deflects ever so slightly.
Granted the collisionsenabled = false is a terrible practice in the first place because it lets allll kinds of little problems though, such as passing through the walls if the player is close enough to the wall.
Can anyone tell me if there is a way to have something like early out that checks on a collision before the physics gets a hold of it?
I'm playing with early out collision stuff right now.
The problem I'm trying to solve is that when I have my ball flying around I only want it to collide sometimes with players and sometimes not.
Early out collisions have half the problem solved, the ball won't collide with a player from the opposite team if the shot type is a pass.
The actual shooting is the problem. My end goal is to have a chance to intercept, a chance to miss entirely (no collision) and a chance to block and deflect the ball.
The deflect and block work fine in the collision delegate, but the pass through doesn't work so well. If I put the pass through chance in the early out test it makes a check 30-40+ times on the way and through that player. So something I only want to happen once (to give fair odds with the other two options) happens 30-40 times. If I put the pass through in the collision delegate, the physics engine gets a crack at it before my delegate, so I can get it to pass through (with a CollisionsEnabled = false for 150 ms on a schedule) but it deflects ever so slightly.
Granted the collisionsenabled = false is a terrible practice in the first place because it lets allll kinds of little problems though, such as passing through the walls if the player is close enough to the wall.
Can anyone tell me if there is a way to have something like early out that checks on a collision before the physics gets a hold of it?
Torque Owner Cosmic Logic
I'm pretty sure I solved it. (In case anybody else needs something like this)
All I did was create two lists on my ball object. One storing a list of animated sprites (Lp), and one storing lists of test results (Lr).
Every time it ran through the early out test, it checks to see if theirObject was in the list, if it was it uses the stored Lr, if not it added it to the list of Lp and stored the decided true/false in Lr.
So now, every time it passes through it will only decide once and then use that decision for every single early out test from thereon.
I've also got a reset method that resets certain variables on that ball that I use and just added on a couple lines clearing out those lists.
So far so good :D
I'm not sure if this is best practise but it works for now, if anyone has any input on the solution that would be appreciated as well.