Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | DoGot |
I have an issue where when I move my player character, any bullets that it fires also move with it.
I have a separate scene which is my main scene, and have imported my main charecter as an instance into that scene
Code below:
extends KinematicBody2D
export (int) var speed = 200
var velocity = Vector2()
var main = get_tree().get_root()
export(PackedScene) var Bullet = preload(“res://Bulletthin.tscn”)
func shoot():
var b = Bullet.instance()
add_child(b)
b.transform = $Muzzle.transform
func get_input():
velocity = Vector2()
if Input.is_action_pressed(‘right’):
velocity.x += 1
rotation_degrees = 90
if Input.is_action_pressed(‘left’):
velocity.x -= 1
rotation_degrees = -90
if Input.is_action_pressed(‘down’):
velocity.y += 1
rotation_degrees = 180
if Input.is_action_pressed(‘up’):
velocity.y -= 1
rotation_degrees = 360
velocity = velocity.normalized() * speed
func _physics_process(delta):
get_input()
velocity = move_and_slide(velocity)
if Input.is_action_pressed(“fire”):
shoot()