Player sometimes shoot at an incredible speed for no reason

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By KramchayDig

I just simply code on getting the player to basically shoot diagonally but I get this weird sudden incredible speed of the bullet even I never added to increase its speed and I want to know how do I keep the player’s bullet to show no unusual behavior when I’m shooting.

If you look closely on the gifs you can see one bullet just suddenly shoot through at an incredible speed.
enter image description here

Here’s another sighting of the unusual glitch
enter image description here

Here are the codes I just made for this project:

PLAYER CODE:

    extends KinematicBody

    var velocity = Vector3(0,0,0)

    export var SPEED : float = 8

    const UP = Vector3(0,1,0)

    func _ready():

pass

    func _input(event):

if Input.is_key_pressed(KEY_ESCAPE):
	get_tree().quit()

if Input.is_action_just_pressed("shoot"):
	if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
		instantiate()
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

pass



   func _physics_process(delta):

var g = Vector3(0,-39.8,0)

velocity += g * delta

if Input.is_action_pressed("right") and Input.is_action_pressed("left"):
	velocity.x = 0
elif Input.is_action_pressed("right"):
	velocity.x = SPEED
elif Input.is_action_pressed("left"):
	velocity.x = -SPEED
else:
	velocity.x = lerp(velocity.x,0,.75)

if Input.is_action_pressed("forward") and Input.is_action_pressed("backward"):
	velocity.z = 0
elif Input.is_action_pressed("backward"):
	velocity.z = SPEED
elif Input.is_action_pressed("forward"):
	
	velocity.z = -SPEED
else:
	velocity.z = lerp(velocity.z,0,.75)

if is_on_floor():
	if Input.is_action_pressed("jump"):
		velocity.y = 18
		pass
	pass

velocity = move_and_slide(velocity, UP)
print(velocity)

#velocity.y = min(velocity.y, max_falling_speed)

pass

   func instantiate():

var bullet = preload("res://Bullet.tscn").instance()
get_parent().add_child(bullet)
bullet.global_transform.origin = global_transform.origin #+ Vector3(1,0,-2)
bullet.direction = Vector3(-1,0,-1)

THE BULLET CODE:

    extends KinematicBody

    var direction = Vector3()
    var bulletSpeed = 20

    var timer = null
    export var countdown : float = 5
    export var one_shot : bool = false

    func _ready():
timer = Timer.new()

add_child(timer) 
timer.wait_time = countdown
timer.start() 
timer.one_shot = one_shot
pass 

   func _physics_process(delta):

if timer.time_left == 0:
	queue_free()

var velocity = direction * bulletSpeed * delta
var collision = move_and_collide(velocity)
if(collision):
	
	if(collision.collider.name != "Player"):
		print("My Test")
		free()
	else:
		print(collision)
	
	pass

pass

Looking forward to see answers.

Does the glitch still happen when you do not move the character and/or shoot at slow rate?

BraindeadBZH | 2019-07-22 15:19