mirror of
				https://github.com/GayPizzaSpecifications/voxelotl-engine.git
				synced 2025-11-04 10:59:39 +00:00 
			
		
		
		
	buffer jump input
This commit is contained in:
		@ -22,6 +22,7 @@ struct Player {
 | 
			
		||||
  private var _rotation = SIMD2<Float>.zero
 | 
			
		||||
 | 
			
		||||
  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 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)
 | 
			
		||||
 | 
			
		||||
      // Jumping
 | 
			
		||||
      if self._onGround {
 | 
			
		||||
        if pad.pressed(.east) {
 | 
			
		||||
          self._velocity.y = Self.jumpVelocity
 | 
			
		||||
          self._onGround = false
 | 
			
		||||
      if pad.pressed(.east) {
 | 
			
		||||
        self._shouldJump = 0.3
 | 
			
		||||
      } else if self._shouldJump != .none {
 | 
			
		||||
        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)
 | 
			
		||||
      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
 | 
			
		||||
		Reference in New Issue
	
	Block a user