Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody3D
- var SPEED = 10.0
- var StandingSpeed = 10.0
- var JUMP_VELOCITY = 20.0
- var gravity = 70.0
- var MouseMovement = Vector2(0.0, 0.0)
- var Sensitivity = 0.01
- var DiveSpeed = 32.0
- var ControllerSensitivity = 2.5
- var DiveHeight = 5.0
- var GDiveSpeed = 26.0
- var GDiveHeight = 8.0
- var BDiveSpeed = 60.0
- var BDiveHeight = 15.0
- var DiveWait = 0.5
- var DiveTimer = 0.0
- var TerminalVelocity = 40.0
- var NormalTerm = 40.0
- var WallTerm = 5.0
- var CameraNode
- var CrouchSpeed = 2.5
- var Acceleration = 60.0
- var NormalAcceleration = 60.0
- var Deceleration = 100.0
- var DashDeceleration = 70.0
- var NormalDeceleration = 100.0
- var IsBombing = false
- var IsJumping = false
- var IsWallSliding = false
- var BombDiveTimer = 0.0
- var BombDiveWait = 0.15
- func _ready():
- CameraNode = get_node("Node3D")
- func _physics_process(delta):
- #handle gravity and jump
- if not is_on_floor() and velocity.y > -TerminalVelocity:
- velocity.y -= gravity * delta
- if Input.is_action_pressed("jump") and (is_on_floor() or IsWallSliding) and not IsJumping:
- velocity.y = JUMP_VELOCITY
- IsJumping = true
- if Input.is_action_just_released("jump"):
- IsJumping = false
- #handle input
- var input_dir = Input.get_vector("control_left", "control_right", "control_up", "control_down")
- Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
- #handle movement
- var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
- if direction:
- velocity.x = move_toward(velocity.x, direction.x * SPEED, delta * Acceleration)
- velocity.z = move_toward(velocity.z, direction.z * SPEED, delta * Acceleration)
- else:
- velocity.x = move_toward(velocity.x, 0, delta * Deceleration)
- velocity.z = move_toward(velocity.z, 0, delta * Deceleration)
- #handle bomb
- if Input.is_action_just_pressed("bomb") and not is_on_floor() and not IsBombing:
- IsBombing = true
- velocity.y = -TerminalVelocity
- if is_on_floor():
- if IsBombing:
- IsBombing = false
- BombDiveTimer = BombDiveWait
- Deceleration = NormalDeceleration
- Acceleration = NormalAcceleration
- #handle crouch
- if Input.is_action_just_pressed("crouch"):
- get_node("CollisionShape3D").get_shape().height = 0.4
- get_node("MeshInstance3D").get_mesh().height = 1.0
- SPEED = CrouchSpeed
- if Input.is_action_just_released("crouch"):
- get_node("CollisionShape3D").get_shape().height = 1.0
- get_node("MeshInstance3D").get_mesh().height = 1.6
- SPEED = StandingSpeed
- #handle dive
- if direction and Input.is_action_just_pressed("dive") and DiveTimer < 0:
- if is_on_floor():
- if BombDiveTimer >= 0:
- velocity.x += BDiveSpeed * direction.x
- velocity.z += BDiveSpeed * direction.z
- velocity.y += BDiveHeight
- else:
- velocity.x += GDiveSpeed * direction.x
- velocity.z += GDiveSpeed * direction.z
- velocity.y += GDiveHeight
- else:
- velocity.x += DiveSpeed * direction.x
- velocity.z += DiveSpeed * direction.z
- velocity.y += DiveHeight
- DiveTimer = DiveWait
- Deceleration = DashDeceleration
- Acceleration = DashDeceleration
- DiveTimer -= delta
- BombDiveTimer -= delta
- #handle rotation
- rotate(Vector3.UP, MouseMovement.x * -Sensitivity)
- rotate(Vector3.UP, Input.get_axis("camera_left", "camera_right") * delta * -ControllerSensitivity)
- move_and_slide()
- MouseMovement = Vector2.ZERO
- if get_slide_collision_count() != 0 and not is_on_floor():
- TerminalVelocity = WallTerm
- IsWallSliding = true
- else:
- IsWallSliding = false
- TerminalVelocity = NormalTerm
- if Input.is_action_just_pressed("exit"):
- get_tree().quit()
- func _input(event):
- if event is InputEventMouseMotion:
- MouseMovement = event.relative
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement