Godot Version
4.5
Question
`so, I am trying to have a racing minigame where you pick your moves like a deckbuilder. So when you hit the first button it should move your character forward, and button 2 moves your character forward and to the left. The issue is that it moves the character to the coordinates relative to the center of the world, not relative to the character. so the buttons move the character to one specific spot. Also, when you open the scene it moves the character from the bottom of the screen to the center without any input.
Thank you!!! `
extends CharacterBody2D
Called when the node enters the scene tree for the first time.
var speed = 100
var node_y_position = position.y
var node_x_position = position.x
var new_position = Vector2(node_x_position, node_y_position - speed)
var hardleft = Vector2(node_x_position - .5speed, node_y_position - .5speed)
var hardright = Vector2(node_x_position + .5speed, node_y_position - .5speed)
var bigforward = Vector2(node_x_position, node_y_position - 1.5speed)
var smallleft = Vector2(node_x_position - .25speed, node_y_position - speed)
var smallright = Vector2(node_x_position + .25*speed, node_y_position - speed)
var nomove = Vector2(node_x_position, node_y_position)
var target= position
func _ready() → void:
target=nomove
_physics_process(velocity)
Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _process(delta: float) → void:
pass
func _on_button_pressed() → void:
target = new_position
func _physics_process(delta):
velocity = position.direction_to(target) * speed
if position.distance_to(target) > 10:
move_and_slide()
func _on_button_2_pressed() → void:
target = hardleft
_physics_process(velocity)