# my movement code does not work can someone help

Attention Topic was automatically imported from the old Question2Answer platform.

I’m a Artist defo not a coder so need some help with the code it does not compile could some one knowledgeable help me out

extends KinematicBody2D

const MOVE_SPEED = 500

#Jump

export var fall_gravity_scale := 150.0

export var low_jump_gravity_scale := 100.0

export var jump_power := 500.0

var jump_released = false

#Physics

var velocity = Vector2()

var earth_gravity = 9.807 # m/s^2

export var gravity_scale := 100.0

var on_floor = false

func _physics_process(delta):

var move_dir = 0

if Input.is_action_pressed(“rightmove”):
move_dir += 1

if Input.is_action_pressed(“leftmove”):
move_dir -= 1

move_and_slide(Vector2(move_dir * MOVE_SPEED, y_velocity), Vector2(0, -1))

if Input.is_action_just_released(“jump”):
jump_released = true

#Applying gravity to player

velocity += Vector2.DOWN * earth_gravity * gravity_scale * delta

#Jump Physics

if velocity.y > 0: #Player is falling
#Falling action is faster than jumping action | Like in mario

#On falling we apply a second gravity to the player

#We apply ((gravity_scale + fall_gravity_scale) * earth_gravity) gravity on the player

velocity += Vector2.DOWN * earth_gravity * fall_gravity_scale * delta

elif velocity.y < 0 && jump_released: #Player is jumping

#Jump Height depends on how long you will hold key

#If we release the jump before reaching the max height

#We apply ((gravity_scale + low_jump_gravity_scale) * earth_gravity) gravity on the player

#It result on a lower jump

velocity += Vector2.DOWN * earth_gravity * low_jump_gravity_scale * delta

if on_floor:

if Input.is_action_just_pressed(“jump”):

velocity = Vector2.UP * jump_power #Normal Jump action

jump_released = false

velocity = move_and_slide(velocity, Vector2.UP)

if is_on_floor(): on_floor = true

else: on_floor = false

could you please put it more friendly like this? There is a button with brackets at the top of the editor…

``````extends RigidBody2D

export (int) var kick_force = 300

GLOBAL.kicker = self

var physics_linear_velocity
func _integrate_forces(state):
if physics_linear_velocity:
linear_velocity = physics_linear_velocity
physics_linear_velocity = null

func kick (direction, kick_scale):
print(kick_scale)
physics_linear_velocity = direction.normalized() * kick_force * kick_scale

func point_at(direction):
arrow_kick.point_at(direction)
``````

fershopls | 2019-11-26 18:24

I can at least provide you my player’s moving script. What I also have added to mine is the code to play certain animations with the movement of the character. I also added the code for the player to shoot if want to use that.

``````const SPEED = 250
const GRAVITY = 10
const JUMP_POWER = -500
const FLOOR = Vector2(0, -1)

var velocity = Vector2()

var jump = false
var jump_speed = 10
var on_ground = false
var can_move = true
var is_attacking = false

func _physics_process(delta):
if Input.is_action_pressed("forward"):
if is_attacking == false || is_on_floor() == false:
velocity.x = SPEED
if is_attacking == false:
\$AnimatedSprite.play("run")
\$AnimatedSprite.flip_h = false
if sign(\$Position2D.position.x) == -1:
\$Position2D.position.x *= -1
elif Input.is_action_pressed("backward"):
if is_attacking == false || is_on_floor() == false:
velocity.x = -SPEED
if is_attacking == false:
\$AnimatedSprite.play("run")
\$AnimatedSprite.flip_h = true
if sign(\$Position2D.position.x) == 1:
\$Position2D.position.x *= -1
else:
velocity.x = 0
if on_ground == true && is_attacking == false:
\$AnimatedSprite.play("idle")

if Input.is_action_pressed("jump"):
if is_attacking == false:
if on_ground == true:
velocity.y = JUMP_POWER
on_ground = false
\$AnimatedSprite.play("jump")
if Input.is_action_just_pressed("shoot") && is_attacking == false:
if is_on_floor():
velocity.x = 0
is_attacking = true
\$AnimatedSprite.play("attack")
var plasmablast = PLASMABLAST.instance()
if sign(\$Position2D.position.x) == 1:
plasmablast.set_plasmablast_direction(1)
else:
plasmablast.set_plasmablast_direction(-1)