Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | iluvyou6000 |
Hello, i am new to godot and i’m having some trouble making the bullets shoot at a certain speed. when my mouse is near my character the bullets will move slowly and if it’s farther it will go too fast. Can someone help me out ?
thank you.
this is my player scene
extends StaticBody2D
export var BulletScene : PackedScene
onready var arrowSprite = $Position2D/ArrowSprite
onready var arrow2D = $Position2D
var mousePosition
func _ready():
mousePosition = get_global_mouse_position()
func _process(delta):
if Input.is_action_pressed("shoot"):
print(mousePosition)
mousePosition = get_local_mouse_position()
arrow2D.look_at(get_global_mouse_position())
shoot()
func shoot():
var bulletInstance = BulletScene.instance()
var main = get_tree().current_scene
main.add_child(bulletInstance)
bulletInstance.global_position = arrowSprite.global_position
bulletInstance.shootDirection(mousePosition)
My bullet scene
extends Area2D
var bulletSpeed = 10
var dir
func _process(delta):
position += dir * bulletSpeed * delta
func shootDirection(mouseDirection):
dir = mouseDirection
func _on_VisibilityNotifier2D_screen_exited():
queue_free()