Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | CosmicNerd6505 |
So I have a KinematicBody2D acting as my bullet, and it shoots in the direction of my mouse. However, I noticed that if my mouse position is farther away from my gun position, the bullet shoots much faster, and if it is closer to my gun position, the bullet shoots much slower. I was wondering if I could somehow make it so that the bullet’s speed is the same despite the vector. Here is my code:
Weapon code:
func shoot():
var mouse_pos = get_global_mouse_pos()
var pos = get_global_pos()
var direction = mouse_pos - pos
direction.normalized()
bullet.shoot(direction) # pass rotation to bullet
bullet code:
func shoot(direction):
var _direction = direction
set_fixed_process(true)
func _fixed_process(delta):
var vel = _direction*bullet_speed*delta
move(vel)