Hello. I’m pretty new to Godot nearly 1 month of first of using the engine and i have ran in to a problem .
until now i have only made simple games following tutorials making games where you can move in all four directions and so i thought its finally time to make a platformer .
So i started following a tutorial by heartbeast
and thing were going pretty smoothly until i tried adding gravity and things just stopped working
i added gravity like in the tutorial and my charecter woundnt move left or right i have to press the up button more than once for the charecter to jump.
Here is the code please someone help i hhave spent hours trying to fix it and im loosing my mind :
extends CharacterBody2D
var Velocity = Vector2.ZERO
const acc = 150
const fric = 170
var Direct_x
func _physics_process(delta):
apply_gravity()
if Input.is_action_just_pressed('ui_up'):
Velocity.y -= 150
Direct_x = Input.get_action_strength('ui_right')-Input.get_action_strength('ui_left')
if Direct_x == 0 :
friction()
else:
accelaration(Direct_x)
move_and_collide(Velocity*delta)
func accelaration(amount):
Velocity.x = move_toward(Velocity.x,acc*amount,10)
func friction():
Velocity.x = move_toward(Velocity.x,0,25)
func apply_gravity():
Velocity.y += 4