![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | X |
Hey guys!
I had a ship (RigidBody2D) that shot a beam (Area2D). But when the ship rotate the beam still goes in the same direction.
The code of the Ship:
func Fire():
var new_shot = shot.instance()
get_parent().add_child(new_shot)
new_shot.User = self
new_shot.set_dir(0, -1)
new_shot.position = $Position2D.global_position
And the code of the Shot:
var dir = Vector2 ()
var Power = 1
export var Speed = 50
var vel = Vector2()
var User
func set_dir(x, y):
if y > 0:
$AnimatedSprite.flip_v = true
dir = Vector2(x, y)
func _process(delta):
vel = dir * Vector2(Speed, Speed) * delta
translate(vel)