0 votes

So basically, I have a square like player made from a kinematicbody2d, a sprite and a collisionshape2d(square). I also have a maze of "walls" setup. Yet, when I navigate my player against a wall he seems to move into it until about half way. Next, he vigorously jumps back. Doing this repetitively makes him look as though he is teleporting back and forth. All I want is for him to stop moving once he is touching one of the walls. Any clues? I pasted the code below if that helps.

extends KinematicBody2D
var velocity=Vector2(0,0)
var WALK_SPEED=25

func ready():
set
process(true)
self.getchild(0).setscale(Vector2(0.05,0.05))
self.getchild(1).setscale(Vector2(0.05,0.05))
set_pos(Vector2(31,32))
pass

func process(delta):
if (Input.is
actionpressed("uileft")):
velocity.x = - WALKSPEED
velocity.y=0
elif (Input.is
actionpressed("uiright")):
velocity.x = WALKSPEED
velocity.y=0
elif (Input.is
actionpressed("uiup")):
velocity.y = -WALKSPEED
velocity.x=0
elif (Input.is
actionpressed("uidown")):
velocity.y = WALK_SPEED
velocity.x=0
else:
velocity.x = 0
velocity.y=0

var motion = velocity * delta
motion = move(motion)

pass
asked Sep 11 in Engine by RobinGerst99 (20 points)

You should fix your code formatting. You can either indent four spaces:

like this

Or use the "{}" button in the formatting menu above.

As it stands, it's impossible to tell if your code is indented properly.

As far as I can see, your code only moves a body using standard 4-way directions and move, but you are using _process instead of _fixed_process.
Also, did you have a look at the official introduction to KinematicBody2D? http://docs.godotengine.org/en/stable/learning/features/physics/kinematic_character_2d.html

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.