Hi there.
I have a player that spawns bullets in front of it, so when the player moves fast it gets hit by it's own bullet.
How do I make the bullet instance at player velocity + bullet speed (so the player can't catch it's own bullet)?
Player is a RigidBody2D that has position 2d as muzzle
From the miuzzle script:
extends Position2D
func shoot():
if can_shoot == false:
return false
if can_shoot == true:
var bullet = Bullet.instance()
bullet.global_position = global_position
bullet.global_rotation = global_rotation
bullet.set_as_toplevel(true)
add_child(bullet)
From bullet script:
extends KinematicBody2D #BULLET
export (int) var bullet_speed
func _physics_process(delta):
var velocity = Vector2 (0, bullet_speed).rotated (global_rotation)
global_position += velocity * delta
Any help appreciated - and specifics even more.
Thanks!