< Summary

Class:Wobble
Assembly:Test
File(s):D:/--UnityProject/VR/VRExplorer_subjects/EscapeGameVR/Assets/Scripts/Test/Wobble.cs
Covered lines:23
Uncovered lines:0
Coverable lines:23
Total lines:59
Line coverage:100% (23 of 23)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:3
Method coverage:100% (3 of 3)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Wobble()0%000100%
Start()0%000100%
Update()0%000100%

File(s)

D:/--UnityProject/VR/VRExplorer_subjects/EscapeGameVR/Assets/Scripts/Test/Wobble.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5public class Wobble : MonoBehaviour
 6{
 7    Renderer rend;
 8    Vector3 lastPos;
 9    Vector3 velocity;
 10    Vector3 lastRot;
 11    Vector3 angularVelocity;
 1312    [SerializeField] private float MaxWobble = 0.03f;
 1313    [SerializeField] private float WobbleSpeed = 1f;
 1314    [SerializeField] private float Recovery = 1f;
 15    float wobbleAmountX;
 16    float wobbleAmountZ;
 17    float wobbleAmountToAddX;
 18    float wobbleAmountToAddZ;
 19    float pulse;
 1320    float time = 0.5f;
 21
 22    // Use this for initialization
 23    void Start()
 624    {
 625        rend = GetComponent<Renderer>();
 626    }
 27    private void Update()
 888828    {
 888829        time += Time.deltaTime;
 30        // decrease wobble over time
 888831        wobbleAmountToAddX = Mathf.Lerp(wobbleAmountToAddX, 0, Time.deltaTime * (Recovery));
 888832        wobbleAmountToAddZ = Mathf.Lerp(wobbleAmountToAddZ, 0, Time.deltaTime * (Recovery));
 33
 34        // make a sine wave of the decreasing wobble
 888835        pulse = 2 * Mathf.PI * WobbleSpeed;
 888836        wobbleAmountX = wobbleAmountToAddX * Mathf.Sin(pulse * time);
 888837        wobbleAmountZ = wobbleAmountToAddZ * Mathf.Sin(pulse * time);
 38
 39        // send it to the shader
 888840        rend.material.SetFloat("_WobbleX", wobbleAmountX);
 888841        rend.material.SetFloat("_WobbleZ", wobbleAmountZ);
 42
 43        // velocity
 888844        velocity = (lastPos - transform.position) / Time.deltaTime;
 888845        angularVelocity = transform.rotation.eulerAngles - lastRot;
 46
 47
 48        // add clamped velocity to wobble
 888849        wobbleAmountToAddX += Mathf.Clamp((velocity.x + (angularVelocity.z * 0.2f)) * MaxWobble, -MaxWobble, MaxWobble);
 888850        wobbleAmountToAddZ += Mathf.Clamp((velocity.z + (angularVelocity.x * 0.2f)) * MaxWobble, -MaxWobble, MaxWobble);
 51
 52        // keep last position
 888853        lastPos = transform.position;
 888854        lastRot = transform.rotation.eulerAngles;
 888855    }
 56
 57
 58
 59}

Methods/Properties

Wobble()
Start()
Update()