|
|
|
 |
Attention |
Topic was automatically imported from the old Question2Answer platform. |
 |
Asked By |
ripull125 |
extends CharacterBody2D
@export var move_speed : float = 100
func _physics_process(_delta):
var input_direction = Vector2(Input.get_action_strength(“right”)-Input.get_action_strength(“left”), Input.get_action_strength(“backward”)-Input.get_action_strength(“forward”))
var velocity = input_direction * move_speed
move_and_slide()
print(input_direction)
|
|
|
 |
Reply From: |
ShatteredReality |
First off, you can use Input.get_vector()
for this. Also you want to call normalize()
on it too. Second, velocity
is already a variable in CharacterBody2D. No need to redefine it. Just remove the var
at the start of the line.
|
|
|
 |
Reply From: |
crossbito |
You are using a local variable called “velocity”. Instead, you should use the “velocity” variable from “CharacterBody2D”.
Change:
var velocity = inputdirection * movespeed
to:
velocity = inputdirection * movespeed
This will ensure that you are modifying the “velocity” variable of the “CharacterBody2D” object instead of creating a new local variable.