0 votes

Character.gd:

extends KinematicBody2D


# Public variables
export(float) var speed = 50


# Private variables
var speed_x = 0
var speed_y = 0
var direction = Vector2()


# Constants
const GRAVITY = 512


func _ready():
    pass


func _physics_process(delta):
    # Gravity force
    direction.y = speed_y * delta
    speed_y += GRAVITY * delta

Mario.gd:

extends "res://core/character/Character.gd"


# Private variables
var jumping = false


# Constants
const JUMP_FORCE = 256


# References
onready var Sprite = $Sprite


func _input(event):
    if event.is_action_pressed("move_left"):
        Sprite.scale.x = -1
        Sprite.animation = "walking"
    elif event.is_action_pressed("move_right"):
        Sprite.scale.x = 1
        Sprite.animation = "walking"
    elif event.is_action_pressed("jump"):
        if not jumping:
            jumping = true
            speed_y = -JUMP_FORCE


func _process(delta):
    direction.x = int(Input.is_action_pressed("move_right")) - int(Input.is_action_pressed("move_left"))

    if direction.x == 0:
        Sprite.animation = "idle"


func _physics_process(delta):
    move_and_slide(direction * speed)

    if is_on_wall():
        speed_y = 0
        jumping = false

    var collision

    for i in get_slide_count():
        collision = get_slide_collision(i)

    if collision != null:
        pass
in Engine by (682 points)
edited by

1 Answer

+1 vote
Best answer

Use physics_process instead of process

by (232 points)
selected by
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.