unity 地震

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;
}

}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值