Hey there all! so I'm currently stuck and any help would be appreciated.
So im making a top down shooter and im trying to get the bullets to not track with the players turning. currently what they are doing is essentially firing in a straight line, and whenever the player turns the bullets turn to match their movement.
I want the bullets to remain at their set firing position whenever the player rotates so they stay on their intended path.
Below is the code im using to accomplish what im already doing:
extends CharacterBody2D
#free floating variables - variables not contained in a func or if statement
var bullet_speed = 2000
var bullet = preload("res://bullet.tscn")
var shellcasing = preload("res://shellcasing.tscn")
#All code below is functional
var movespeed = 500
func restart():
get_tree().reload_current_scene()
func _process(_delta):
if Input.is_action_just_pressed("escape"):
get_tree().quit()
if Input.is_action_just_pressed("levelrestart"):
restart()
func _ready():
pass
func _physics_process(_delta):
global_rotation = global_position.direction_to(get_global_mouse_position()).angle() + PI/2.0
var move_direction = Input.get_vector("left", "right", "up", "down")
velocity = move_direction * movespeed
move_and_slide()
#Below is a test fire function called func Shoot():
if Input.is_action_just_pressed("shoot"):
shoot()
func shoot():
var s = shellcasing.instantiate()
add_child(s)
s.transform = $Ejector.transform
var b = bullet.instantiate()
add_child(b)
b.transform = $Muzzle.transform
#Below is the code that the tutorial said to use, but It did nothing
#var bullet_instance = bullet.instantiate()
#bullet_instance.position = get_global_position()
#bullet_instance.rotation_degrees = rotation_degrees
#bullet_instance.apply_impulse(Vector2(),Vector2(bullet_speed,0).rotated(rotation))
#get_tree().get_root.call_deferred("add_child",bullet_instance)
I was following a few seperate tutorials, and one of them said to simply set the bullets using a .transform_global command which didnt work.
Im still very new to designing games in godot, and in general so any help anyone can give would be awesome! If you need anything clarified please let me know.