From 57eaeff00597f8ae6289b935dec0c408e21759ab Mon Sep 17 00:00:00 2001 From: Malfurious Date: Sun, 30 Oct 2022 01:59:06 -0400 Subject: Convert script tabs to spaces and other whitespace fixes! Signed-off-by: Malfurious --- assets/view_model/ViewModel.gd | 134 ++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 67 deletions(-) (limited to 'assets/view_model/ViewModel.gd') diff --git a/assets/view_model/ViewModel.gd b/assets/view_model/ViewModel.gd index 949bfab..96e0f3e 100644 --- a/assets/view_model/ViewModel.gd +++ b/assets/view_model/ViewModel.gd @@ -14,78 +14,78 @@ onready var spring_arm = $Anchor/SpringArm onready var fps_label = $fps_label func _ready(): - Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) func _process(_delta): - # The character model and the spring arm anchor are independent to allow them to rotate - # independently. Recouple their translations here so that the camera follows the model through - # space. - anchor.translation = character.translation - - # Update fps counter in HUD - fps_label.text = "FPS: " + str(Engine.get_frames_per_second()) + # The character model and the spring arm anchor are independent to allow them to rotate + # independently. Recouple their translations here so that the camera follows the model through + # space. + anchor.translation = character.translation + + # Update fps counter in HUD + fps_label.text = "FPS: " + str(Engine.get_frames_per_second()) func _physics_process(delta): - # Intended movement direction with the rotational angle adjusted by the camera's aim direction - var move_direction = Vector3.ZERO - move_direction.x = Input.get_action_strength("right") - Input.get_action_strength("left") - move_direction.z = Input.get_action_strength("back") - Input.get_action_strength("forward") - move_direction = move_direction.rotated(Vector3.UP, spring_arm.rotation.y).normalized() - - # Update velocity by new movement direction and continued effect of "gravity" - velocity.x = move_direction.x * movement_speed - velocity.z = move_direction.z * movement_speed - velocity.y -= gravity * delta - - # Snap vector management: set to ZERO to enable jumping, DOWN otherwise to stick to surfaces. - # Allow jump action for only one frame if already standing on a floor. - var just_landed = character.is_on_floor() and snap == Vector3.ZERO - var jump = character.is_on_floor() and Input.is_action_just_pressed("jump") - if jump: - velocity.y = jump_strength - snap = Vector3.ZERO - elif just_landed: - snap = Vector3.DOWN - - # Move character. Param 4 (true) means stop on slopes - velocity = character.move_and_slide_with_snap(velocity, snap, Vector3.UP, true) - - # Update character look direction to face towards aiming if firing - if Input.is_action_pressed("fire"): - character.look_angle = spring_arm.rotation.y - character.weapon_pitch = -spring_arm.rotation.x - # Update character look direction if moved - elif move_direction.length() > 0.2: - var look_direction = Vector2(-velocity.z, -velocity.x) - character.look_angle = look_direction.angle() - character.weapon_pitch = 0 - else: - character.weapon_pitch = 0 - - # Handle extra player inputs - character.is_firing = Input.is_action_pressed("fire") - - if Input.is_action_just_pressed("ping"): - cycle_parent() - - if Input.is_action_just_pressed("menu"): - get_tree().quit() + # Intended movement direction with the rotational angle adjusted by the camera's aim direction + var move_direction = Vector3.ZERO + move_direction.x = Input.get_action_strength("right") - Input.get_action_strength("left") + move_direction.z = Input.get_action_strength("back") - Input.get_action_strength("forward") + move_direction = move_direction.rotated(Vector3.UP, spring_arm.rotation.y).normalized() + + # Update velocity by new movement direction and continued effect of "gravity" + velocity.x = move_direction.x * movement_speed + velocity.z = move_direction.z * movement_speed + velocity.y -= gravity * delta + + # Snap vector management: set to ZERO to enable jumping, DOWN otherwise to stick to surfaces. + # Allow jump action for only one frame if already standing on a floor. + var just_landed = character.is_on_floor() and snap == Vector3.ZERO + var jump = character.is_on_floor() and Input.is_action_just_pressed("jump") + if jump: + velocity.y = jump_strength + snap = Vector3.ZERO + elif just_landed: + snap = Vector3.DOWN + + # Move character. Param 4 (true) means stop on slopes + velocity = character.move_and_slide_with_snap(velocity, snap, Vector3.UP, true) + + # Update character look direction to face towards aiming if firing + if Input.is_action_pressed("fire"): + character.look_angle = spring_arm.rotation.y + character.weapon_pitch = -spring_arm.rotation.x + # Update character look direction if moved + elif move_direction.length() > 0.2: + var look_direction = Vector2(-velocity.z, -velocity.x) + character.look_angle = look_direction.angle() + character.weapon_pitch = 0 + else: + character.weapon_pitch = 0 + + # Handle extra player inputs + character.is_firing = Input.is_action_pressed("fire") + + if Input.is_action_just_pressed("ping"): + cycle_parent() + + if Input.is_action_just_pressed("menu"): + get_tree().quit() func _unhandled_input(event): - # Implement mouse aim direction - if event is InputEventMouseMotion: - spring_arm.rotation_degrees.x -= event.relative.y * aim_sensitivity - spring_arm.rotation_degrees.x = clamp(spring_arm.rotation_degrees.x, -90, 90) - - spring_arm.rotation_degrees.y -= event.relative.x * aim_sensitivity - spring_arm.rotation_degrees.y = wrapf(spring_arm.rotation_degrees.y, 0, 360) + # Implement mouse aim direction + if event is InputEventMouseMotion: + spring_arm.rotation_degrees.x -= event.relative.y * aim_sensitivity + spring_arm.rotation_degrees.x = clamp(spring_arm.rotation_degrees.x, -90, 90) + + spring_arm.rotation_degrees.y -= event.relative.x * aim_sensitivity + spring_arm.rotation_degrees.y = wrapf(spring_arm.rotation_degrees.y, 0, 360) func cycle_parent(): - var parents = get_tree().get_nodes_in_group("players") - var idx = parents.find(character) - - if idx < 0 or idx == parents.size() - 1: - if parents.size() > 0: - character = parents[0] - else: - character = parents[idx + 1] + var parents = get_tree().get_nodes_in_group("players") + var idx = parents.find(character) + + if idx < 0 or idx == parents.size() - 1: + if parents.size() > 0: + character = parents[0] + else: + character = parents[idx + 1] -- cgit v1.2.3