Hi all, Harshdeep here,
I'm totally new in game development side. I followed BornCG in Youtube and made exactly same 3D game. But, now I want to implement some jumping function with disable on gravity. ( means user can't jump while in the air. ). I tried but, failed to implement it.
My controller code.
extends KinematicBody
var velocity = Vector3(0,0,0)
const SPEED = 5
const ROTATE = 5
func _ready():
#Game Background Music
var BackgroundMusic = get_node("BackgroundMusic/AudioStreamPlayer3D")
BackgroundMusic.play()
#pass
func _physics_process(delta):
#RollerBall(Player) Control.
if Input.is_action_pressed("ui_right") and Input.is_action_pressed("ui_left"):
velocity.x = 0
elif Input.is_action_pressed("ui_right"):
velocity.x = SPEED
$MeshInstance.rotate_z(deg2rad(-ROTATE))
elif Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
$MeshInstance.rotate_z(deg2rad(ROTATE))
else:
velocity.x = lerp(velocity.x,0,0.1)
if Input.is_action_pressed("ui_up") and Input.is_action_pressed("ui_down"):
velocity.z = 0
elif Input.is_action_pressed("ui_up"):
velocity.z = -SPEED
$MeshInstance.rotate_x(deg2rad(-ROTATE))
elif Input.is_action_pressed("ui_down"):
velocity.z = SPEED
$MeshInstance.rotate_x(deg2rad(ROTATE))
else:
velocity.z = lerp(velocity.z,0,0.1)
move_and_slide(velocity)