Regional collision detect question
by KaiserImpact · in Torque 2D Beginner · 01/07/2014 (8:15 am) · 4 replies
Hello all. First of all i've just started on torque2d programming and would like to apologize if its a really simple question.
Currently i am working with enemy AI, whereby the enemy has an idle state and chasing state. Such as if player were to be near the enemy, the enemy will start to chase the player and when the player had ran far enough, the enemy will go back to idle. I've done both of the state but i have no idea how to change the state if the condition were to be met.
My initial idea is somewhat to be like this.(Sorry i do not know how to post picture)
XXX
XOX
XXX
Whereby "O" stands for the enemy itself and "X" stands for the region that the enemy will change state. Once player enters region "X", enemy "O" will chase the player and if the player leaves region "X", enemy "O" will back to idle state.
So my first question is, how to create this area of region(prefered to be circle shape) that will enable the enemy to change state. And also, both of my enemy and player are dynamic body type. If enemy were to collide with the player, the player will get bounced back due to physic. My second question is how do i remove this annoying bounce back? i've tried to set TestToy.Player.setLinearVelocityX(0.0) and Y to 0 in the onCollision function but that doesn't seems to be working.
Currently i am working with enemy AI, whereby the enemy has an idle state and chasing state. Such as if player were to be near the enemy, the enemy will start to chase the player and when the player had ran far enough, the enemy will go back to idle. I've done both of the state but i have no idea how to change the state if the condition were to be met.
My initial idea is somewhat to be like this.(Sorry i do not know how to post picture)
XXX
XOX
XXX
Whereby "O" stands for the enemy itself and "X" stands for the region that the enemy will change state. Once player enters region "X", enemy "O" will chase the player and if the player leaves region "X", enemy "O" will back to idle state.
So my first question is, how to create this area of region(prefered to be circle shape) that will enable the enemy to change state. And also, both of my enemy and player are dynamic body type. If enemy were to collide with the player, the player will get bounced back due to physic. My second question is how do i remove this annoying bounce back? i've tried to set TestToy.Player.setLinearVelocityX(0.0) and Y to 0 in the onCollision function but that doesn't seems to be working.
About the author
#2
to my current undestanding, I would attach a circular collision shape to that enemy body, and set the shape to be a sensor so it won't interfere with the physics. Then read the collision information on every update (or in the enter/leave callback method) to determine if the player is within that shape.
What is the camera orientation in the game? If it's a top-down view, maybe the kinematic body type would suffice for the player, in case you don't need it bouncing around by things.
01/07/2014 (10:48 am)
Hi there,to my current undestanding, I would attach a circular collision shape to that enemy body, and set the shape to be a sensor so it won't interfere with the physics. Then read the collision information on every update (or in the enter/leave callback method) to determine if the player is within that shape.
What is the camera orientation in the game? If it's a top-down view, maybe the kinematic body type would suffice for the player, in case you don't need it bouncing around by things.
#3
01/07/2014 (10:55 am)
Check it in the enter/leave callbacks. It would be inefficient to check every tick. If the player is kinematic, it will not affected by any forces except velocities applied by the player. Keep that in mind.
#4
01/07/2014 (12:54 pm)
Just to avoid confusion with any terminology used- the onEnter/onLeave callbacks are for collision shapes attached to Triggers. For collision shapes attached to SceneObjects, Sprites, etc, the callbacks are onCollision/onEndCollision.
Employee Michael Perry
ZombieShortbus