mirror of
https://github.com/GayPizzaSpecifications/voxelotl-engine.git
synced 2025-08-02 13:00:53 +00:00
buffer jump input
This commit is contained in:
parent
bcc56956b3
commit
b7dba429cf
@ -22,6 +22,7 @@ struct Player {
|
|||||||
private var _rotation = SIMD2<Float>.zero
|
private var _rotation = SIMD2<Float>.zero
|
||||||
|
|
||||||
private var _onGround: Bool = false
|
private var _onGround: Bool = false
|
||||||
|
private var _shouldJump: Optional<Float> = .none
|
||||||
|
|
||||||
public var position: SIMD3<Float> { get { self._position } set { self._position = newValue } }
|
public var position: SIMD3<Float> { get { self._position } set { self._position = newValue } }
|
||||||
public var velocity: SIMD3<Float> { get { self._velocity } set { self._velocity = newValue } }
|
public var velocity: SIMD3<Float> { get { self._velocity } set { self._velocity = newValue } }
|
||||||
@ -46,12 +47,23 @@ struct Player {
|
|||||||
self._rotation.y = self._rotation.y.clamp(-.pi * 0.5, .pi * 0.5)
|
self._rotation.y = self._rotation.y.clamp(-.pi * 0.5, .pi * 0.5)
|
||||||
|
|
||||||
// Jumping
|
// Jumping
|
||||||
if self._onGround {
|
if pad.pressed(.east) {
|
||||||
if pad.pressed(.east) {
|
self._shouldJump = 0.3
|
||||||
self._velocity.y = Self.jumpVelocity
|
} else if self._shouldJump != .none {
|
||||||
self._onGround = false
|
if pad.down(.east) {
|
||||||
|
self._shouldJump! -= deltaTime
|
||||||
|
if self._shouldJump! <= 0.0 {
|
||||||
|
self._shouldJump = .none
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self._shouldJump = .none
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if self._onGround && self._shouldJump != .none {
|
||||||
|
self._velocity.y = Self.jumpVelocity
|
||||||
|
self._onGround = false
|
||||||
|
self._shouldJump = .none
|
||||||
|
}
|
||||||
|
|
||||||
// Movement (slower in air than on ground)
|
// Movement (slower in air than on ground)
|
||||||
let movement = pad.leftStick.cardinalDeadzone(min: 0.1, max: 1)
|
let movement = pad.leftStick.cardinalDeadzone(min: 0.1, max: 1)
|
||||||
|
8
Sources/Voxelotl/Random.swift
Normal file
8
Sources/Voxelotl/Random.swift
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
//
|
||||||
|
// Random.swift
|
||||||
|
// voxelotl
|
||||||
|
//
|
||||||
|
// Created by a dinosaur on 20/8/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
Loading…
Reference in New Issue
Block a user