Just started recently, I've been trying to make a movable character (WASD)(kinematicBody2D) for 2 days but nothing works

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bluestorm_321

Because of some issues I’m using Godot 2.1.6
Ive followed tutorials on version 2.1 and 3 and used so many different codes by different people but none ever work.
Heres some code I tried apart from the other 10 I used:

    extends KinematicBody2D
# class variables
const MOVE_SPEED = 8

func _ready():
	set_process(true)
	pass

func _process(delta):
	# variables
	var newpos = get_pos()
	# move left
	if(Input.is_action_pressed("move_left")):
		newpos = Vector2(get_pos().x - MOVE_SPEED, get_pos().y)
		if(get_viewport_rect().has_point(newpos)):
			set_pos(newpos)

Can Anyone tell me whats wrong?

:bust_in_silhouette: Reply From: Magso

For a Kinematicbody2D you can use

extends KinematicBody2D
export var MOVE_SPEED = 8
func _process(delta):
    move_and_slide(Vector2(Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left"), Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")) * MOVE_SPEED)

but I’m not sure if Input.get_action_strength() is in Godot 2 but you should be using the move_and_slide() method for Kinematicbodies as it works with the physics engine, whereas other ways of moving nodes like set_position are direct and will cause clipping.

Also (just to make sure) is move_left in your input map?

yea I’ve mapped ui_left and Ive checked several times to make sure. The code u gave doesn’t work. I think at this point it could somehow be a problem of my laptop. Though it’s functional and works fine, it’s very old.

Bluestorm_321 | 2020-05-29 07:42