Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody3D
- @export var move_rampup_curve_tex: CurveTexture = preload("res://player/move_rampup_curve.curvetex")
- @onready var move_rampup_curve = move_rampup_curve_tex.get_curve()
- @export var move_rampup_speed: float = 10
- @export var speed: float = 5.0
- var current_move_rampup_x: float = 0
- var current_move_rampup_z: float = 0
- @export var jump_velocity: float = 4.5
- @export var camera_boom: SpringArm3D
- @export var mouse_sens: float = 1
- @export var vertical_look_limit = 90
- @export var shoulder_offset: float = 0
- func _ready() -> void:
- Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
- func _input(event: InputEvent) -> void:
- if event is InputEventMouseMotion:
- var mouse_delta = event.screen_relative
- rotate_y(deg_to_rad(-mouse_delta.x * mouse_sens)) #Should be rotating player?????
- camera_boom.rotation_degrees = Vector3(clamp(camera_boom.rotation_degrees.x + (-mouse_delta.y * mouse_sens), -vertical_look_limit, vertical_look_limit),
- rotation_degrees.y,
- rotation_degrees.z
- )
- Input.warp_mouse(Vector2(get_viewport().size.x/2, get_viewport().size.y/2))
- func _physics_process(delta: float) -> void:
- # Add the gravity.
- if not is_on_floor():
- velocity += get_gravity() * delta
- # Handle jump.
- if Input.is_action_just_pressed("jump") and is_on_floor():
- velocity.y = jump_velocity
- # Get the input direction and handle the movement/deceleration.
- # As good practice, you should replace UI actions with custom gameplay actions.
- var input_dir := Input.get_vector("strafe_left", "strafe_right", "move_forward", "move_back")
- var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
- if input_dir.x != 0:
- current_move_rampup_x += move_toward(0, 1, delta * move_rampup_speed)
- else:
- current_move_rampup_x = 0
- if input_dir.y != 0:
- current_move_rampup_z += move_toward(0, 1, delta * move_rampup_speed)
- else:
- current_move_rampup_z = 0
- if direction:
- velocity.x = direction.x * speed * move_rampup_curve.sample(current_move_rampup_x)
- velocity.z = direction.z * speed * move_rampup_curve.sample(current_move_rampup_z)
- else:
- velocity.x = move_toward(velocity.x, 0, speed)
- velocity.z = move_toward(velocity.z, 0, speed)
- move_and_slide()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement