0 votes

I have already done all the animation for that, it's just the scripting part, I am relatively new to gdscript, I tried

if player.getpos(x) < object.getpos(x):
    #player looks at the object whether going forward or backward
elif player.getpos(x) > object.getpos(x):
    #player looks backwards at the object whether going forward or backward
if player.getpos(y) > object.getpos(y):
     #player looks down at the object whether going forward or backward

None worked. I want the player to start looking at the object as soon as the object enters the camera. This is intended for finding secrets in a level

in Engine by (119 points)
recategorized by

Maybe you should make add the player's direction to the if?

1 Answer

0 votes

Well, you have to use global positions (get_global_pos()), not local.

As for looking at, there is sample "look at" project in your godot instalation :) Just run it from Project list, its very simple piece of code, arrows are pointing at cursor. Maybe you will have to add or substract PI/2 or PI/4, becouse arrows in that sample project are "heading down", "y is front" (or idk how to say it..) and i am pretty sure head of your character isnt :) You will see, feel free to ask another question ;)

And, last thing, you have to add VisibilityNotifier2D on your secret location (but beware known bug #1269) connect to enter_screen and exit_screen signals (events) to start your look at procedure. You can add_to_group them in "secrets" group, find them get_tree().get_nodes_in_group("secrets") and connect with simple foreach statement (see tutorial)

edit: get_global_position() is of course get_global_pos()

by (241 points)
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 Frequently asked questions and 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 [email protected] with your username.