0 votes

i want to know how to flip while following main player, the characters are isometric not top down

Godot version 3.2
in Projects by (12 points)

1 Answer

0 votes

You can set the scale to -1 in order to flip the enemy. Calculate the angle between the enemy and the player character and then set the scale to -1 if the angle is greater than 180 degrees or whatever value you want.

This will only give you two directions that the enemy can face, though. If you want more, you would have to create more sprites for the enemy.

by (4,476 points)

help with the code if possible

I tried coding an answer to your problem, but then I realized that I have no clue what your sprites look like, so I wouldn't know at what angle to flip them. What do your sprites look like?

hers the link to a a sample screenshot of my character

majorly i just want the enemy to face the relevant direction while walking towards the enemy . all the sprites for all the direction up,down.right and left are available

Okay, since the sprite you linked (I don't see it in your comment but it was in the email sent to me) is facing to the left, you want to flip it whenever the player character is 90+ degrees away from it (positive and negative 90). If the sprite was facing to the right, you'd want to do the opposite - flip it when it was between -90 and 90 degrees.

Here is the code (note that degrees are in radians)

func _physics_process(delta):
    var angle = global_position.angle_to_point(player.global_position)
    if abs(angle) > PI/2:
        scale.x = -1
    else:
        scale.x = 1
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories