![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | jcg |
extends KinematicBody2D
const ACCELERATION = 10
const MAX_SPEED = 100
const FRICTION = 400
var velocity = Vector2.ZERO
func _physics_prcess(delta):
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength(“ui_right”) - Input.get_action_strength(“ui_left”)
input_vector.y = Input.get_action_strength(“ui_down”) - Input.get_action_strength(“ui_up”)
input_vector = input_vector.normalized()
if input_vector != Vector2.ZERO:
velocity += input_vector * ACCELERATION * delta
else:
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
move_and_collide(velocity * delta)
im watching ‘hearth beast’ “make a rpg game in godot” but i cant move my character. can someone tell me how to make my character move???
It looks like it should work. What actual values are you passing to move_and_collide? (Put a breakpoint on it).
SteveSmith | 2022-12-19 12:48
You have written-
func physicsprcess(delta):
It is-
func _physics_process(delta):
also there are many typos like in ‘get action strength’.
You can achieve the same of what you are trying to achieve by this code:
extends KinematicBody2D
const ACCELERATION = 800
const FRICTION = 800
const MAX_SPEED = 50
var velocity = Vector2.ZERO
func _physics_process(delta):
var input = Vector2.ZERO
input.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
input.y = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
if input != Vector2.ZERO:
velocity = velocity.move_toward(input * MAX_SPEED, ACCELERATION * delta)
else:
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
velocity = move_and_slide(velocity)
Savage_Reaper | 2022-12-20 11:29