collision line set in sprite angle

S

stepup2000

Guest
is there anyway you could use a collision line going in the same direction your enemy is facing? lets say you use a collision line as a detector for your enemy to check if he sees you or not. i dont have extremely much experience with gml yet but i tried this:

//step event

image_angle = direction
if collision_line(x, y, direction, direction, obj_player, false, false) {

room_restart()
}

it doesnt seem to work tho. the collion line is always aimed towards the top left corner and will never change direction even when the object changes direction
 
The 3rd and 4th arguments are not directional arguments, they are x and y coordinates. Something like this should work:
Code:
var view_distance = 200;
var tx = x+lengthdir_x(view_distance,direction);
var ty = y+lengthdir_y(view_distance,direction);
if (collision_line(x,y,tx,ty,obj_player,false,false)) {
   room_restart();
}
lengthdir_x and y are functions that basically turn a vector (direction+view_distance is a vector) into coordinates. So you just grab your x and y coordinates, figure out how far you want the enemy to see (view_distance) and then use the direction in the lengthdir to return the x and y coordinates of the collision line based around whatever direction the instance is facing.

For instance, you could fake a moon rotating a planet with this:
Moon step:
Code:
var orbit_dist = 500;
x = obj_planet.x+lengthdir_x(orbit_dist,dir);
y = obj_planet.y+lengthdir_y(orbit_dist,dir);
dir++;
The moon will stay a set distance from the planet, because orbit_dist isn't changing, but incrementing the dir variable means it will rotate around it.
 
S

stepup2000

Guest
The 3rd and 4th arguments are not directional arguments, they are x and y coordinates. Something like this should work:
Code:
var view_distance = 200;
var tx = x+lengthdir_x(view_distance,direction);
var ty = y+lengthdir_y(view_distance,direction);
if (collision_line(x,y,tx,ty,obj_player,false,false)) {
   room_restart();
}
lengthdir_x and y are functions that basically turn a vector (direction+view_distance is a vector) into coordinates. So you just grab your x and y coordinates, figure out how far you want the enemy to see (view_distance) and then use the direction in the lengthdir to return the x and y coordinates of the collision line based around whatever direction the instance is facing.

For instance, you could fake a moon rotating a planet with this:
Moon step:
Code:
var orbit_dist = 500;
x = obj_planet.x+lengthdir_x(orbit_dist,dir);
y = obj_planet.y+lengthdir_y(orbit_dist,dir);
dir++;
The moon will stay a set distance from the planet, because orbit_dist isn't changing, but incrementing the dir variable means it will rotate around it.
thank you so much! i have been breaking my head over this for hours haha. the only thing that bothers me now is this:
so instead of restarting the room i made the enemy chase the player

//step

var view_distance = 800;
var tx = x+lengthdir_x(view_distance,direction);
var ty = y+lengthdir_y(view_distance,direction);
if (collision_line(x,y,tx,ty,obj_player,false,false)) {

image_angle = point_direction(x,y,obj_man.x, obj_man.y);
mp_potential_step(obj_man.x, obj_man.y, true, 1)
}
else {

exit
}
now the enemy can look trough walls, do you know how we fix that?
 
Last edited by a moderator:
Top