SOLVED teleportation in an area & check for walls

Rexzqy

Member
Hi fellow game makers,

I want to write a code which teleports wolf object to their leader when too far away from the leader. I dont really want to teleport to the leader's exact position, maybe like in a circular area that has 150 radius. Something like If point_distance(x,y,leader.x,leader.y) > 400, then x = random_range(-75,75) and y = random_range(-75,75). But what is the best way to check for wall and if there's wall, then choose another coordinate? do i have to use the "do..until"? Will it lag the game if most of that 150 radius area is covered with wall?

Any help is greatly appreciated!!
 
If you want a circular radius, use lengthdir_x/y as your example will utilize a box. Instead of starting with a general random coordinate, consider the situation. Unless something buggy is going on, the leader is pretty much guaranteed to be in a wall-free position. Cast a ray from the leader in a random direction, and pick a spot along that line that comes before a wall or the 150 pixel radius. If there is little to no clearance from that ray (such as the leader being right next to a wall), start over. This will also keep the group together, instead of doing something like teleporting the distant wolf to an area separate from the leader.
 

Rexzqy

Member
If you want a circular radius, use lengthdir_x/y as your example will utilize a box. Instead of starting with a general random coordinate, consider the situation. Unless something buggy is going on, the leader is pretty much guaranteed to be in a wall-free position. Cast a ray from the leader in a random direction, and pick a spot along that line that comes before a wall or the 150 pixel radius. If there is little to no clearance from that ray (such as the leader being right next to a wall), start over. This will also keep the group together, instead of doing something like teleporting the distant wolf to an area separate from the leader.
Thx man! will try that!
 

Rexzqy

Member
If you want a circular radius, use lengthdir_x/y as your example will utilize a box. Instead of starting with a general random coordinate, consider the situation. Unless something buggy is going on, the leader is pretty much guaranteed to be in a wall-free position. Cast a ray from the leader in a random direction, and pick a spot along that line that comes before a wall or the 150 pixel radius. If there is little to no clearance from that ray (such as the leader being right next to a wall), start over. This will also keep the group together, instead of doing something like teleporting the distant wolf to an area separate from the leader.
kinda took a different approach after i realized that maybe random point isnt that important since this is happening outside of player's view

did something like this:

GML:
if point_distance(leader.x,leader.y,x,y) > max_wander_distance && leader != true
{
    if position_meeting(leader.xprevious,leader.yprevious,obj_wall) = false
    {
    x = leader.xprevious;
    y = leader.yprevious;
    }
}
yeah it will put all wolves in this group to the exact same spot, but its outside of players view and they will wander to different locations soon so doesnt matter.

Still huge thx for your help!!
 
Top