using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class zhendong : MonoBehaviour
{
private Vector3 _lastPosition;
private Vector3 _lastRotation;
public Vector3 MaximumTranslationShake = Vector3.one * .75f;
public float shake;
public float _trauma;
float time = 0;
public float TraumaExponent = 1;
public Vector3 MaximumAngularShake = Vector3.one * 5;
public Transform o;
public float MaxLevel = 0.4f;
float Stress=0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
var previousRotation = _lastRotation;
var previousPosition = _lastPosition;
time += Time.deltaTime;
Stress += 0.001F;
_trauma = Mathf.Clamp01(_trauma + Stress);
//设置位移幅度
if (_trauma <= MaxLevel)
{
_trauma = time * 0.1f;
print("1");
}
else
{
_trauma = MaxLevel;
print("2");
}
//pow 平方
shake = Mathf.Pow(_trauma, TraumaExponent);
//设定位移角度
_lastPosition = new Vector3(
MaximumTranslationShake.x * (Mathf.PerlinNoise(0, Time.time * 25) * 30 - 1),
MaximumTranslationShake.y * (Mathf.PerlinNoise(1, Time.time * 25) * 30 - 1),
MaximumTranslationShake.z * (Mathf.PerlinNoise(2, Time.time * 5) * 30 - 1)
) * shake;
_lastRotation = new Vector3(
MaximumAngularShake.x * (Mathf.PerlinNoise(3, Time.time * 5) * 20 - 1),
MaximumAngularShake.y * (Mathf.PerlinNoise(4, Time.time * 25) * 20 - 1), 0
//MaximumAngularShake.z * (Mathf.PerlinNoise(5, Time.time * 5) * 2 - 1)
) * shake;
o.localPosition += _lastPosition - previousPosition;
}
}