Hi, im quite new into this Godot thing, im currently trying to do something that makes the enemy spin to face the player constantly, after looking for hours to a solution to this, ive seen that the most common line for this is the following:
This, however, causes the enemy sprite to spin endlessly without focusing on the player, i tried to fix this by just spinning the sprite 90° degrees but it doesnt stop spinning, its clear that somethings not right and i would like to know if theres something i can do to fix this.
If you all need some additional info, this scrip is attached to a CharacterBody2D node with just a sprite node.
Ive seen it used a lot around this one code, though it could be what made the sprite rotate to follow the player since just using look_at doesnt do the work for some reason
Very interesting. look_at should alter a Node2D’s rotation, the next rotate(PI/2) line shouldn’t continously spin with look_at or any other rotation set.
The player node ( in my case, named “phage” since the original script has its name instead of player in the second line) is another CharacterBody2D Node defined with 4 child nodes, a collision, a timer dedicated to the cooldown for bullets, a marker that generates said bullets and the sprite.
as for the _process snippet, i tried it out but its still spun nonstop.
The look_at() should be enough to rotate your Node. See here my quick dirty demo showing that it in fact works. I made it so that it follows the mouse_position for simplicity.
extends Node2D
func _physics_process(delta):
var position: Vector2 = get_viewport().get_camera_2d().get_global_mouse_position()
look_at(position)
You can see that the code is not the problem. There has to be something else in your project that prevents the proper rotation. Would that be ok if you shared your project, e.g. via GitHub? This way we can debug and help you much easier. At the moment it’s like looking for a needle in a haystack, blindfolded.