Hundreds of features to explore
Games made in Construct
Your questions answered
Trusted by schools and universities worldwide
Free education resources to use in the classroom
Students do not need accounts with us
What we believe
We are in this together
World class complete documentation
Official and community submitted guides
Learn and share with other game developers
Upload and play games from the Construct community
Game development stories & opinions
I am making a targeting system for an RPG. I want to be able to test whether the player character's sprite is within certain angles of the target. For example, if the player character is within the cone of 35 to 145 degrees of their target, I want them to face "up", and if the player character is within the cone of 136 to 225 degrees, I want them to face "right" etc. I just can't figure out how construct wants me to write that code. Any help would be appreciated.
P.S. I don't want to rotate the sprite to face that target. I just am working with up, right, left, and down.
You need to use angle() expression.
angle(player.x, player.y, target.x, target.y) is within 45 degrees of 90
Player set animation to "FaceDown"
Or you can use "Between angles" condition - angle(..) is between 45 and 135
Develop games in your browser. Powerful, performant & highly capable.
Thanks for the reply. Just so I understand, in the second example would I just be entering in the player.x, player.y values in the parentheses?
angle() expression returns an angle between two points. It requires 4 parameters: point1 x, point1 y, point2 x, point2 y.
For example, angle(character.x, character.y, enemy.x, enemy.y)
Thanks a bunch!
I've tried it... it isn't working. Could you make a mock-up capx to show me how you do it?
This is perfect, thank you. That really cleared it up!