Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody3D
- @onready var camera = $Cam/Camera3D
- @onready var cam = $Cam
- const MOUSE_SENSITIVITY = 0.25
- const GRAVITY = -20.0
- const JUMP_SPEED = 7
- const SPEED = 6
- const ACCEL = 12.0
- var vel = Vector3.ZERO
- var currentvel = Vector3.ZERO
- var dir = Vector3.ZERO
- func _ready():
- Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
- func _physics_process(delta):
- dir = Vector3.ZERO
- if Input.is_action_pressed("forward"):
- dir -= camera.global_transform.basis.z
- if Input.is_action_pressed("back"):
- dir += camera.global_transform.basis.z
- if Input.is_action_pressed("left"):
- dir -= camera.global_transform.basis.x
- if Input.is_action_pressed("right"):
- dir += camera.global_transform.basis.x
- dir = dir.normalized()
- var target_vel = dir * SPEED
- currentvel = currentvel.lerp(target_vel, ACCEL * delta)
- vel.x = currentvel.x
- vel.z = currentvel.z
- vel.y += GRAVITY * delta
- if Input.is_action_just_pressed("jump") and is_on_floor():
- vel.y = JUMP_SPEED
- set_velocity(vel)
- move_and_slide()
- func _input(event):
- if event is InputEventMouseMotion:
- cam.rotate_x(deg_to_rad(event.relative.y * -MOUSE_SENSITIVITY))
- cam.rotation_degrees.x = clamp(cam.rotation_degrees.x, -70, 45)
- self.rotate_y(deg_to_rad(event.relative.x * -MOUSE_SENSITIVITY))
- #RAGDEV
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement