Godot Version
4.3 stable
Question
I have an object (CharacterBody2D) and another position written in Vector2. How can I move object to this position by adding velocity?
4.3 stable
I have an object (CharacterBody2D) and another position written in Vector2. How can I move object to this position by adding velocity?
extends CharacterBody2D
var another_position : Vector2 #Set your other position here
var direction : Vector2 = Vector2.ZERO
var acceleration : int = 100 #Change this for faster/slower acceleration
func _ready() -> void:
direction = global_position.direction_to(another_position)
func _physics_process(delta : float) -> void:
velocity += direction * acceleration * delta
move_and_slide()
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.