• 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!

How to check if a player is facing another...

B

BigCat

Guest
I'm building a top-down shooter.

I have a target-A which basically sits in the center of the room
I have ships which fly around the room in various formation patterns or whatever.
The ships have laserbeams that fire directly forward.

I want the ships, as they fly about the room - to check whether they are facing target-A - and if so - shoot their lasers.

I have everything figured out - EXCEPT - how to check if an instance is facing another instance.
I've tried: if direction = point_angle ( x, y, target.x, target.y )
I've tried: if image_angle = point_angle ( x, y, target.x, target.y )

But I'm missing something or using it wrong - I dunno. It runs fine and doesn't throw any errors that I can see. But it just doesn't pull the trigger when it's supposed to.

My best guess - was that the two values are really never the same because of the rotation of the enemy ships. They rotate at a specific rate per frame which likely makes the two sides of the equation basically impossible without a relative range in place.

SO - My next attempt was something like
IF direction - point_angle (x,y, target.x, target.y) <= 20
But nope... that didn't do diddly either.

So now i'm sad. *sigh*

Any ideas or insight would be great.
I'm using DND - but I'm not afraid to write complex expressions.
 
Last edited by a moderator:

NightFrost

Member
Directions and angles are floats, so it might be that the facing's off by 0.0001 degrees, but that still means they ain't equal and no lasers get fired. Instead you need to check that the difference is small enough, then shoot the laser. In that, angle_difference() is your friend.
 
B

BigCat

Guest
BOOM!

@NightFrost saves my bacon! :)

By getting the angle_difference between image_angle, and point_angle ; I was able to create a safe fire zone it could find.

THANK YOU !!!! :)
 
Top