|
collision avoidance
#325338
05/26/10 05:51
05/26/10 05:51
|
Joined: Mar 2009
Posts: 25
kholis
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 25
|
entity C is a player. entity A and entity B will follow player movement in any formation. if player keep moving straight, i want to make entity A turn left and walk in same direction of cube side without touching yellow area. entity B is also the same but he will turn right (according to the obstacle in front of him) need some help. thanks
|
|
|
Re: collision avoidance
[Re: kholis]
#325366
05/26/10 10:05
05/26/10 10:05
|
Joined: Feb 2009
Posts: 2,154
Damocles_
Expert
|
Expert
Joined: Feb 2009
Posts: 2,154
|
Do you move them by clicking to a location (like in an RTS) Or by moving the player directly (like in a 3rd person game)?
In the case of an RTS, the position within the formation are calculated first, and the Units move toward their target-points. In the case the targetpoints are in an inpassable area, you need a function to look for a point closest to the targetpoint, wich can be accessed. (you could try that out by looking around in a "circle", until the new targetpoint is on a passable terrain), and set this as new targetpoint.
--
In the case of a 3rd person game, its more tricky, as the units will move constantly relative to the players position, and their favorable formation position.
I would simply first develop a normal obstacle avoidance (such as using traces to the front, and turn the unit when a fronttrace gets too close to a wall) Such that the unit first tries to walk to the position in the formation, and in the second step rotates to avoid getting too close to a wall)
After a timeinterval (like 2 seconds) the unit tries to turn and walk towards the formation-position again.
This way the units will head towards the formation position, but avoid obstacles as long as needed. But on a free terrain, they will exacly follow the formation then.
Good would be for the unit to constantly turn towards the formation-target (every frame), but once the avoidance-trace hiths a wall in a savety-distance, the unit will stop turning towards the formation.target every frame, and rather rotate sidewasy, until the trace does not hit a wall. (it continious walking, as long as it does not get too far away from the player) The unit checks then every 2 seconds if a trace towards the formation-target is possibe. If yes, it switches back to the normal state.
Instead of turning before an obstacle, you can also let the units step sideways, and keep turning towards to formation-target. You should use traces to the side then as well. (its really mainly testing out wich works best)
|
|
|
Re: collision avoidance
[Re: 3run]
#327550
06/07/10 04:53
06/07/10 04:53
|
Joined: Mar 2009
Posts: 25
kholis
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 25
|
what function better i use to detect collision? c_scan or EVENT_BLOCK? or any other? is there any function can be used to determine entity hit angle (α) from obstacle?
Last edited by kholis; 06/07/10 04:55.
|
|
|
Re: collision avoidance
[Re: kholis]
#327952
06/09/10 14:21
06/09/10 14:21
|
Joined: Mar 2009
Posts: 146 USA
paracharlie
Member
|
Member
Joined: Mar 2009
Posts: 146
USA
|
You could use c_content. This is some code that George wrote in aum88 for unanswered questions. It uses c_content for obstacle avoidance and it does work very well. You could adapt this in your code and just play with the settings, to get them set the way you want.
// the road is clear? then rotate the enemy towards the player
if (c_content (content_right.x, 0) + c_content (content_left.x, 0) == 2)
{
vec_set(temp, player.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan, temp); // turn the enemy towards the player
}
if (vec_dist (player.x, my.x) > 500)
{
vec_set(content_right, vector(50, -20, -15));
vec_rotate(content_right, my.pan);
vec_add(content_right.x, my.x);
if (c_content (content_right.x, 0) != 1) // this area isn't clear?
{
my.pan += 5 * time_step; // then rotate the enemy, allowing it to avoid the obstacle
}
vec_set(content_left, vector(50, 20, -15));
vec_rotate(content_left, my.pan);
vec_add(content_left.x, my.x);
if (c_content (content_left.x, 0) != 1) // this area isn't clear?
{
my.pan -= 5 * time_step; // then rotate the enemy, allowing it to avoid the obstacle
}
c_move (my, vector(10 * time_step, 0, 0), nullvector, GLIDE);
ent_animate(my, "run", run_percentage, ANM_CYCLE); // play the "run" animation
run_percentage += 6 * time_step; // "6" controls the animation speed
}
A8 Commercial
|
|
|
Re: collision avoidance
[Re: Widi]
#327962
06/09/10 15:51
06/09/10 15:51
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
I used c_content to make AI, works great, and yep, I work with level blocks only. but turning bots pan till c_content touches something is not that good way, better make bot strafe or even better to make a counter, so when one of the contents touches anything, and bots pan turns, just switch on the counter, and till counter will be equal to some number (60 for example), bot will not turn to player, that way it'll looks more realistic.
|
|
|
|