0 votes

extends KinematicBody2D

const ACCELERATION = 500
const MAX_SPEED = 80
const FRICTION = 500

var velocity = Vector2.ZERO

func physicsprocess(delta):
var inputvector = Vector2.ZERO
vector.x = Input.getactionstrength("uiright") - Input.getactionstrength("uileft")
inputvector.y = Input.getactionstrength("uidown") - Input.getactionstrength("uiup")
vector = input_vector.normalized()

if input_vector != Vector2.ZERO:
    velocity = velocity.move_toward(input_vector * MAX_SPEED * ACCELERATION * delta)
    velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)

move_and_collide(velocity * delta)

This is the code and I am not sure what the problem is. Also i keep getting errors that mention C++ even though I am using gdscript.

Godot version Godot Engine V3.2.3.stable.official
in Engine by (17 points)

The C++ error comes with GDscript error btw, since GDscript isnt a real programming language its made using another (C++) and of course godot itself is a program that was coded in C++ its only natural to get a C++ error

Oh I see, I appreciate the information and will keep that in mind moving forward.

1 Answer

0 votes
Best answer

You are passing a single parameter to the function:
velocity = velocity.move_toward(input_vector * MAX_SPEED * ACCELERATION * delta)
it should go something like this:
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)

by (2,060 points)
selected by

Understood, I will try this. Thank you for your help.

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.