Player Code :
extends Actor
func physicsprocess(delta: float) -> void:
var direction: = getdirection()
velocity = calculatemovevelocity(velocity, direction, speed)
velocity = moveandslide(velocity, FLOORNORMAL)
func getdirection() -> Vector2:
return Vector2(
Input.getactionstrength("moveright") - Input.getactionstrength("moveleft"),
-1.0 if Input.getactionstrength("jump") and ison_floor() else 0.0
)
func calculatemovevelocity(
linearvelocity: Vector2,
speed: Vector2,
direction: Vector2
) -> Vector2:
var newvelocity: = linearvelocity
newvelocity.x = speed.x * direction.x
newvelocity.y += gravity * getphysicsprocessdeltatime()
if direction.y == -1.0:
newvelocity.y = speed.y * direction.y
return new_velocity
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
Actor Code:
extends KinematicBody2D
class_name Actor
const FLOOR_NORMAL: = Vector2.UP
export var speed: = Vector2(300.0,1000.0)
export var gravity: = 4000.0
var velocity: = Vector2.ZERO