Godot Version
4
Question
I followed some tutorials on how to make a top down player but I messed it up trying to change it
4
I followed some tutorials on how to make a top down player but I messed it up trying to change it
extends CharacterBody2D
@export var speed: int = 45
@export var current_dir: = “none”
var moveDirection = 0
var ngm : = 0
func _physics_process(delta):
player_movement(delta)
handleCollision()
move_and_slide()
func player_movement(_delta):
if Input.is_action_pressed("ui_right"):
current_dir = "right"
play_anim(1)
velocity = moveDirection*speed
elif Input.is_action_pressed("ui_left"):
current_dir = "left"
play_anim(1)
velocity = moveDirection*speed
elif Input.is_action_pressed("ui_down"):
current_dir = "down"
play_anim(1)
velocity = moveDirection*speed
elif Input.is_action_pressed("ui_up"):
current_dir = "up"
play_anim(1)
velocity = moveDirection*speed
else:
play_anim(0)
velocity = moveDirection*ngm
move_and_slide()
func play_anim(movement):
var dir = current_dir
var anim = $AnimatedSprite2D
if dir == "right":
anim.flip_h = false
if movement == 1:
anim.play("Side_Walk")
elif movement == 0:
anim.play("Side_Idle")
if dir == "left":
anim.flip_h = true
if movement == 1:
anim.play("Side_Walk")
elif movement == 0:
anim.play("Side_Idle")
if dir == "down":
anim.flip_h = true
if movement == 1:
anim.play("Front_Walk")
elif movement == 0:
anim.play("Front_Idle")
if dir == "up":
anim.flip_h = false
if movement == 1:
anim.play("Back_Walk")
elif movement == 0:
anim.play("Back_Idle")
func handleCollision():
for i in get_slide_collision_count():
var collision = get_slide_collision(i)
var collider = collision.get_collider()
print_debug(collider.name)
I made the ngm variable because i couldnt multiplymove direction by 0 although either way it doesnt work
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.