• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM [sort-of Solved] I need Help with Object sight

Evanski

Raccoon Lord
Forum Staff
Moderator
So basically I want to make the weeping angels from doctor who.

now for those that dont know a statute that moves when you dont look at it.

so I know collision_line exists but that only works as long as there is nothing in between the two objects (angel and player)

I want it so that the angel could have a clear collision_line to the player but as long as the player isnt facing the angel make the angel move to the player
 
You could have the player projecting an object with a sprite that represents its area of vision, and do collision_line between the angel and the player with that object tested. Have the object with 'visible = false' in its create event - it can't be seen, but collision_line will still work with it.
VISION.png

There's other ways, but they're harder to explain here and for you to implement.

As an example - there is an example in the manual of line of sight, but....you'd have to be doing it in the player, and then have the angel accessing the result to know if it should move or not. You can find this in the manual under 'maths' / 'vector functions' / 'dot product'

I won't explain how it works (the line of sight element - accessing variables in another instance is easy), because frankly I have no clue :) It would do what you want, but someone else will have to tell you how to apply it beyond the given example, as I've never figured it out
 
Last edited:

Evanski

Raccoon Lord
Forum Staff
Moderator
You could have the player projecting an object with a sprite that represents its area of vision, and do collision_line between the angel and the player with that object tested. Have the object with 'visible = false' in its create event - it can't be seen, but collision_line will still work with it.
View attachment 17825

There's other ways, but they're harder to explain here and for you to implement.

As an example - there is an example in the manual of line of sight, but....you'd have to be doing it in the player, and then have the angel accessing the result to know if it should move or not. You can find this in the manual under 'maths' / 'vector functions' / 'dot product'

I won't explain how it works (the line of sight element - accessing variables in another instance is easy), because frankly I have no clue :) It would do what you want, but someone else will have to tell you how to apply it beyond the given example, as I've never figured it out
You know I already have an object that is where the player is looking (obj_activate), maybe I could just do the collision_line code to the obj_activate and check to see if the player is in between the obj_activate and Angel then that means the player is not looking at the angel
 

Evanski

Raccoon Lord
Forum Staff
Moderator
You know I already have an object that is where the player is looking (obj_activate), maybe I could just do the collision_line code to the obj_activate and check to see if the player is in between the obj_activate and Angel then that means the player is not looking at the angel
so this works just you would need obj_activate to be the same height as your player sprite
 
Last edited by a moderator:
You know I already have an object that is where the player is looking (obj_activate), maybe I could just do the collision_line code to the obj_activate and check to see if the player is in between the obj_activate and Angel then that means the player is not looking at the angel
One other alternative would be to get the direction the player is looking, and then set an angle either side of that to whatever cone of vision you want. Then you get the angle from the player to the angel, and see if that angle falls within the range you have set:

// assumes that direction as a variable is being set to where the player is facing
Code:
angle_one =  direction - 45;    // the 45 here is just the amount of degree's difference I am taking away from 'direction'
angle_two = direction + 45;     // the 45 here is just the amount of degree's difference I am adding to 'direction'. There is now points 45 degree's either side of the way player is facing
angle_angel = point_direction(x, y, angel.x, angel.y);
angle_diff_one = angle_difference(angle_one, angle_angel);
angle_diff_two = angle_difference(angle_two, angle_angel);
if sign(angle_diff_one) == -1 && sign(angle_diff_two) == 1
{player can see angel}
Angle_difference compares two angles, and finds the relation between them - whether clockwise, or anti clockwise, is the closest distance between the two. When sign is applied to the result of angle_difference you get a value of -1 if its anti clockwise, or 1 if it's clockwise, or 0 if both angles are equal.

If angle_angel is between the two angles you have defined it will return a result that is -1 for one of the checks, and 1 for the other check. This means it is in between the two angles, and therefore seen by the player.

So now you have three ways you can approach this, and just go with whatever you understand best :)
1) Simulate the cone of vision with a sprite
2) Use the line of sight example in the manual
3) Use what I have put above
 
Last edited by a moderator:
Top