Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody3D
- @export var Speed = 10.0
- @export var JumpStrenght = 9.0
- @export var Gravity = 25.0
- var Velocity = Vector3.DOWN
- var SnapVector = Vector3.DOWN
- @onready var CamArm = $CamArm
- @onready var Model = $Model
- func _physics_process(delta):
- Movement(delta)
- func _process(delta):
- window_activity()
- CamArm.position = position
- func Movement(delta):
- var MoveDir = Vector3.ZERO
- MoveDir.x = Input.get_action_strength("Right") - Input.get_action_strength("Left")
- MoveDir.z = Input.get_action_strength("Back") - Input.get_action_strength("Forward")
- MoveDir = MoveDir.rotated(Vector3.UP, CamArm.rotation.y).normalized()
- Velocity.x = MoveDir.x * Speed
- Velocity.z = MoveDir.z * Speed
- Velocity.y -= Gravity * delta
- var JustLanded = is_on_floor() and SnapVector == Vector3.ZERO
- if Input.is_action_just_pressed("Jump") and is_on_floor():
- Velocity.y = JumpStrenght
- SnapVector = Vector3.ZERO
- elif JustLanded:
- SnapVector = Vector3.DOWN
- set_velocity(Velocity)
- set_up_direction(Vector3.UP)
- set_floor_stop_on_slope_enabled(true)
- move_and_slide()
- Velocity = velocity
- if Velocity.length() > 0.2:
- var LookDirection = Vector2(Velocity.z, Velocity.x)
- Model.rotation.y = lerp_angle(Model.rotation.y, LookDirection.angle(), delta*5)
- func window_activity():
- if Input.is_action_just_pressed("ui_cancel") or Input.is_action_just_pressed("Fullscreen"):
- if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
- Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
- else:
- Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement