Godot Version
Godot 4.3
Question
I am struggling to make the bombs I am shooting to go where I click, also the bomb is teleporting not moving,
- List item
Godot 4.3
I am struggling to make the bombs I am shooting to go where I click, also the bomb is teleporting not moving,
Add @onready
to your direction variable declaration
@onready var direction = global_position.direction_to(get_global_mouse_position())
What do you mean it’s teleporting?
It should be rather smoothly going in the direction of the mouse pointer. Maybe try adjusting the “1000” value to match your desired look.
A base-type variable like Vector3 is copied. so when you form the equation global_position.direction_to(mouse_position)
, it runs once, and copies that value to the variable. Like writing down a number, direction
will never change.
By putting this equation inside _physics_process
it will update every frame.
How are you spawning the bombs? May it be that they aren’t “teleporting” but are always spawned at 0,0?
Make sure to paste scripts instead of screen shots
oh sorry didn’t know that, I will do that in the future
I think its because I need to make the projectile as a CharacterBody2d node and add the move_and_slide thing
yeah I think that fixes it
Using move_and_slide()
function on CharacterBody2D
instead of directly changing the position
of Area2D
is indeed a good idea that I can only recommend. This will ensure the bullet actually moves along the velocity
vector and report all collisions on the way.