Hello there! im creating a top down shooter and have watched a few tutorials to do so, but I ran into an issue. When you click the screen, the bullet is shot fine, but if you click close to the character the bullet does something weird and goes inwards before dissapearing. I have a position 2D node attached to my character to set the position where the projectile is being shot, so my guess is that it has something to do with that.
Var direction: Vector2 = (get_global_mouse_position() - player.global_position()). normalized()
newbullet.velocity = direction
newbullet.transform.look_at(direction) # local space look_at
The only thing I made up is the player character global position. I donât know where it can be accessed.
To some degree you donât have to manually rotate the bullet if you can leverage the transforms of nodepos & pos node.
Thanks! It worked, but Iâm having issues with the bullet rotation
onready var player = get_node(".")
func shoot():
var newbullet = pistol_bullet.instance()
get_parent().add_child(newbullet)
newbullet.position = $nodepos/pos.global_position
var bulletdirection: Vector2 = (get_global_mouse_position() - player.get_global_position()).normalized()
newbullet.velocity = bulletdirection
newbullet.transform.look_at(bulletdirection)
in the last line it shows the error nonexistent function âlook_atâ in base âtransform2Dâ
I tried keping it as newbullet.look_at(bulletdirection) but the rotations are set only to the place where the character spawns, when it moves to another location it doesnât work