Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | xoron | |
Old Version | Published before Godot 3 was released. |
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
const ACCELERATION = 10
func _ready():
set_fixed_process(true)
func _fixed_process(delta):
#velocity += GRAVITY * delta
var movement = 1
if(Input.is_key_pressed(KEY_LEFT)):
movement *= -MOVEMENT_SPEED
velocity +=Vector2(-ACCELERATION*MOVEMENT_SPEED*delta, 0)
move(velocity)
if(Input.is_key_pressed(KEY_RIGHT)):
movement *= MOVEMENT_SPEED
velocity +=Vector2(ACCELERATION*MOVEMENT_SPEED*delta, 0)
move(velocity)
velocity +=Vector2(ACCELERATION, 0)
velocity = Vector2(0,0)
i forget to remove movement *= MOVEMENT_SPEED useless
xoron | 2017-06-22 19:36
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.
eons | 2017-06-22 19:45
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.
GameDeveloper1212 | 2017-06-22 19:51
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():
pass
eons | 2017-06-22 20:31
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.
rredesigns | 2017-06-24 19:29