playMaker

Author Topic: How to determine and get the direction where object is facing?  (Read 1257 times)

rechronicle

  • Full Member
  • ***
  • Posts: 119
  • Mystvaldia
    • Indie RPG Creator
How to determine and get the direction where object is facing?
« on: November 03, 2019, 03:58:05 AM »
Hello,

I'm wondering what is the workflow to experiment with the object facing direction?

Things that I want to implement is that the Enemy object will move away(bounce off) from where the SwordHit collider is coming. It's not a physic-based & made in 2D, so I guess it will need to play around with vector2 numbers.

And how to set that 'this' direction is the front of this object? Which then I can use to do any possible things from that direction. Ex: make this object dodge back.

Thank you!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: How to determine and get the direction where object is facing?
« Reply #1 on: November 03, 2019, 03:46:53 PM »
Hi.
in 2D i tend to use get X position on source and target (player / enemy)
then check (player / enemy) greater or less than. if less, enemy = left if greater enemy = right.
You should also set the equal the left or right (your preferred choice)

For the 'Front' of the object depends on how you turn the object (sprite flip, rotate, scale)
But for all of them you should do a compare.

if its top down tho you might need to look into angles.