< Summary

Class:FreeMovementController
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/CharacterController/FreeMovementController.cs
Covered lines:5
Uncovered lines:32
Coverable lines:37
Total lines:84
Line coverage:13.5% (5 of 37)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FreeMovementController()0%110100%
Awake()0%110100%
IsActive()0%2100%
SetActive(...)0%2100%
CalculateMovement()0%2100%
FreeMovement()0%1101000%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/CharacterController/FreeMovementController.cs

#LineLine coverage
 1using DCL.Helpers;
 2using System.Collections;
 3using System.Collections.Generic;
 4using UnityEngine;
 5
 6public class FreeMovementController : MonoBehaviour
 7{
 8
 9    [Header("Movement")]
 59810    public float groundCheckExtraDistance = 0.25f;
 59811    public float movementSpeed = 11f;
 59812    public float runningSpeedMultiplier = 0.36f;
 13
 14    [Header("InputActions")]
 15    public InputAction_Hold sprintAction;
 16
 17    [System.NonSerialized] public CharacterController characterController;
 18
 19    bool isSprinting = false;
 20    bool isActive;
 21
 59822    Vector3 velocity = Vector3.zero;
 23
 024    private Vector3NullableVariable characterForward => CommonScriptableObjects.characterForward;
 25
 026    private Vector3Variable cameraForward => CommonScriptableObjects.cameraForward;
 027    private Vector3Variable cameraRight => CommonScriptableObjects.cameraRight;
 28
 29    [SerializeField] private InputAction_Measurable characterYAxis;
 30    [SerializeField] private InputAction_Measurable characterXAxis;
 31
 119432    private void Awake() { characterController = GetComponent<CharacterController>(); }
 33
 034    public bool IsActive() { return isActive; }
 35
 036    public void SetActive(bool _isActive) { isActive = _isActive; }
 37
 038    public Vector3 CalculateMovement() { return FreeMovement(); }
 39
 40    Vector3 FreeMovement()
 41    {
 042        velocity.x = 0f;
 043        velocity.z = 0f;
 044        velocity.y = 0;
 45
 046        if (characterController.enabled)
 47        {
 048            var speed = movementSpeed * (isSprinting ? runningSpeedMultiplier : 1f);
 49
 050            transform.forward = characterForward.Get().Value;
 51
 052            var xzPlaneForward = Vector3.Scale(cameraForward.Get(), new Vector3(1, 0, 1));
 053            var xzPlaneRight = Vector3.Scale(cameraRight.Get(), new Vector3(1, 0, 1));
 54
 055            Vector3 forwardTarget = Vector3.zero;
 56
 057            if (characterYAxis.GetValue() > 0)
 058                forwardTarget += xzPlaneForward;
 059            if (characterYAxis.GetValue() < 0)
 060                forwardTarget -= xzPlaneForward;
 61
 062            if (characterXAxis.GetValue() > 0)
 063                forwardTarget += xzPlaneRight;
 064            if (characterXAxis.GetValue() < 0)
 065                forwardTarget -= xzPlaneRight;
 66
 67
 068            if (Input.GetKey(KeyCode.Space))
 069                forwardTarget += Vector3.up;
 070            else if (Input.GetKey(KeyCode.X))
 071                forwardTarget += Vector3.down;
 72
 073            forwardTarget.Normalize();
 74
 75
 076            velocity += forwardTarget * speed;
 077            CommonScriptableObjects.playerUnityEulerAngles.Set(transform.eulerAngles);
 78
 079            characterController.Move(velocity * Time.deltaTime);
 80        }
 81
 082        return velocity;
 83    }
 84}