0 votes

This code is well for horizontal player movement if not then what miss i also need to apply jump later sorr for bad physic and math

#Law of Physic 
const GRAVITY = Vector2(0, 30)

# PLayer Velocity
var velocity = Vector2()

# MovementSpeed
const MOVEMENT_SPEED = 100
func _ready():

func _fixed_process(delta):
#velocity += GRAVITY * delta

var movement = 1
    movement *= -MOVEMENT_SPEED
    velocity +=Vector2(-ACCELERATION*MOVEMENT_SPEED*delta, 0)

    movement *= MOVEMENT_SPEED
    velocity +=Vector2(ACCELERATION*MOVEMENT_SPEED*delta, 0)

velocity +=Vector2(ACCELERATION, 0)
velocity = Vector2(0,0)
in Engine by (14 points)
edited by

i forget to remove movement *= MOVEMENT_SPEED useless

I don't understand the question.

Also, you are setting velocity and immediately resetting it to zero in the last 2 lines.

The Kinematic Collision demo has a basic movement script you can look at.

I have a problem, I am trying to learn GDscript I watch lots of tutorials on 2d platform movement but whenever I type func _process(delta)
I always get error "Misplaced func"
and it's really annoying since I want to make games in Godot.

Maybe you have an indentation problem, code blocks are defined by indentation

extends baseclass_if_has_any

var instance_variable
const constant

func func_name(): #class method
    var level1statement
    if condition:
          var level2statement
    level1statement = something_outside_if()

func another_func():

I can spot more than one mistake there, for instance, if you say move() and use 0 for the Y axis, then the player will move horizontally only and will not fall.
Why do you have acceleration if it doesn't even make the object accelerate?

Anyway, with the move() method all you should do is define a vector then just use it. If you can provide an example project it would help a lot to see what you need and what is wrong.

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 Frequently asked questions and 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 [email protected] with your username.