Is there a way to check if collision is happening?
by Brandon · in Torque X 2D · 02/24/2009 (6:15 pm) · 8 replies
I know there is the on collision delegate, but is there a way for something else to check if collision is happening?
Basically I have different steering forces, one is a seeking force that is taking me to an object and then the other is an obstacle avoidance force that lets me avoid obstacles. The problem I'm currently having is I need to combine those in a way that lets me decide which force to use. So when I collide I need to know so I can decide to use the force the on collision delegate produces or continue my seeking force.
Or some other way to do it. Opinions welcomed.
I feel like if I can just poll the collision and check if its happening I can solve the problem pretty easily, though I'm not sure if it's possible.
thanks
Basically I have different steering forces, one is a seeking force that is taking me to an object and then the other is an obstacle avoidance force that lets me avoid obstacles. The problem I'm currently having is I need to combine those in a way that lets me decide which force to use. So when I collide I need to know so I can decide to use the force the on collision delegate produces or continue my seeking force.
Or some other way to do it. Opinions welcomed.
I feel like if I can just poll the collision and check if its happening I can solve the problem pretty easily, though I'm not sure if it's possible.
thanks
#2
I tried something like that. I basically got a value for each steering behavior and add it all up to make my total force and set my velocity to that each tick.
This is problematic for me because the onCollision method would update the collide steering force but I don't really have a way of resetting it when the collision stops so basically the brain kept adding the same value to the total running force.
So I was just thinking if I could say "if colliding consider this force" I could solve that problem.
With your way how would you reset the force so that you don't step on the components updating it? You wouldn't want a continuously cumulative force would you?
02/25/2009 (12:04 pm)
Hey Sean,I tried something like that. I basically got a value for each steering behavior and add it all up to make my total force and set my velocity to that each tick.
This is problematic for me because the onCollision method would update the collide steering force but I don't really have a way of resetting it when the collision stops so basically the brain kept adding the same value to the total running force.
So I was just thinking if I could say "if colliding consider this force" I could solve that problem.
With your way how would you reset the force so that you don't step on the components updating it? You wouldn't want a continuously cumulative force would you?
#3
Why not setting the collision steering force to zero at the start of each calculation?
02/25/2009 (12:22 pm)
Well I guess this gets to the "have yet to implement it" part.Why not setting the collision steering force to zero at the start of each calculation?
#4
Another thing I tried was doing "if collisionforce != 0" add that force then set it to 0. It has the same problem though with being reset in that it needs time to happen before the other steering forces send it back the way it came.. It sort of works though my guy gets just enough bounce to make him eventually get around the object and go on his way, but he's stuck on the object for a bit and just looks very unintelligent.
02/25/2009 (12:33 pm)
Basically the ticks happen so fast that if you set the collide force to 0 each brain tick the onCollision might set the force but it gets set back so fast that the force wont have long enough to be applied.Another thing I tried was doing "if collisionforce != 0" add that force then set it to 0. It has the same problem though with being reset in that it needs time to happen before the other steering forces send it back the way it came.. It sort of works though my guy gets just enough bounce to make him eventually get around the object and go on his way, but he's stuck on the object for a bit and just looks very unintelligent.
#5
What about this: reset the cumulative steering force each tick. In pseudo code something like along these lines:
Another thing to consider if you're agent is bouncing off walls to is extend the range of the obstacle detector and/or change the range of the detector based on the agent's velocity.
02/25/2009 (3:14 pm)
How often are your ticks? Currently I have a counter in mine so the steering force is only updated 3 times per second and I'm thinking 1 or 2 may work just as well.What about this: reset the cumulative steering force each tick. In pseudo code something like along these lines:
cumulativeSteeringForce = 0.0f; cumulativeSteeringFroce = CalculateFlockingForce(); // The collision handler from the obstacle avoidance component // will then add to cumulativeSteeringForce if necessary
Another thing to consider if you're agent is bouncing off walls to is extend the range of the obstacle detector and/or change the range of the detector based on the agent's velocity.
#6
I reset the cumulative force each tick and then I check the obstacle avoidance force. If it is not 0 then I only apply that force and then give it a couple of seconds before I reset it. If it's 0 I apply my other force.
So far this is working. Basically it just gives the avoidance a chance to play out before it starts doing what it was previously trying to do such as seek.
Let me know what you come up with when you get to it. This is not ideal because my guy can get stuck trying to avoid things. Although that may be more of a problem with my obstacle avoidance steering force calculations which I'm still trying to figure out..
02/26/2009 (9:14 am)
Ok I think I sort of have something working.I reset the cumulative force each tick and then I check the obstacle avoidance force. If it is not 0 then I only apply that force and then give it a couple of seconds before I reset it. If it's 0 I apply my other force.
So far this is working. Basically it just gives the avoidance a chance to play out before it starts doing what it was previously trying to do such as seek.
Let me know what you come up with when you get to it. This is not ideal because my guy can get stuck trying to avoid things. Although that may be more of a problem with my obstacle avoidance steering force calculations which I'm still trying to figure out..
#7
Have you tried a running (truncated) sum? It sounds like part of your problem is that your agent is either seeking OR avoiding whereas you probably want him to do a bit of both, i.e., avoid obstacles while he seeks.
02/26/2009 (4:08 pm)
Quote:Let me know what you come up with when you get to it. This is not ideal because my guy can get stuck trying to avoid things. Although that may be more of a problem with my obstacle avoidance steering force calculations which I'm still trying to figure out..
Have you tried a running (truncated) sum? It sounds like part of your problem is that your agent is either seeking OR avoiding whereas you probably want him to do a bit of both, i.e., avoid obstacles while he seeks.
#8
02/27/2009 (7:00 am)
I have not tried it. I need to figure out what my max force should be, then just do the sum and apply the reset timer to the collision force like I have set up now. That should allow the collision to play out while keeping my guy focused on his overall mission.
Torque Owner Sean Monahan
I've been putting some thought to this and haven't actually implemented anything yet but here's what I have for your consideration.
In the TX Book chapter on 2D AI John K. builds an AI Brain component that requires his other AI components be attached to a scene object with the AI Brain. Using this setup: an AI brain that depends on steering behaviors and other AI components I'm thinking that AI brain should have a field "steeringForce" that is update by the individual steering behaviors so you AI makes decisions based on this summed force rather than the individual forces.
For example I'm using a flocking behavior to have my AI allies follow my human player(s). In general the AI agents should simply follow the rules for the flocking behavior. However, if this is all they do they get stuck in the walls and fall off cliffs and the like. Not exactly intelligent. Instead I'm calculating the steering force for flocking and adding that to a cumulative steering force in my brain component. The agents then use this cumulative force to decide how and where to move.
To avoid walls and the like I'm working on the obstacle avoidance behavior we discussed in another thread. In my onCollision delegate I calculate the avoidance steering force and then update the cumulative steering force in my AI brain to make adjustments to avoid obstacles.
Using this approach I can mix and match steering behaviors based on the state of my agents. Disclaimer: like I said above, I haven't actually gotten into all the details of how this will work, but I believe the plan to be a sound one.