|Topic was automatically imported from the old Question2Answer platform.
In my game i have an enemy that starts at the top and moves downward. My plan was for it to shoot out a raycast and hit an invisible collision shape behind the player that is part of the scene, and if it hits the wall instead of the player, compare the x value of the collision to the position of the player (the difference between the height of the invisible wall and the player collision is small so it wouldn’t make much of a difference) and rotate the ship by a little bit to the left or right depending on whether the player is to the left or right of that collision (or if it is hitting the player, go towards the player). This way, the ship would have a little bit of angular velocity so the player has a chance to dodge it since the player can only move left and right. The only problem is that i don’t know how to get the player’s position. I tried i signal but i can’t figure out how to make it work. Does anyone know the best way to do this? I don’t want to do tree navigation, so anyone have any other idea that will work?
I want the code to look about like this:
if $Raycast.get_collider().get_name() == 'Back':
if $Raycast.get_collision_point().x < PlayerPosition.x:
set_rotation_degree(get_rotation_degree() + rotatespeed)
set_rotation_degree(get_rotation_degree() - rotatespeed)
Side question but also important, it is telling me that that set_rotation_degree isn’t how you set the rotation degree. What is the set function for rotation?
edit: i figured out the rotate() function, but how do i make the ship move in the direction it is facing?