Net.Like.Xue.Tokyo/Assets/BITKit/UnityPluginsSupport/FPS/Recoil.cs

31 lines
981 B
C#
Raw Normal View History

2024-11-03 16:42:23 +08:00
/* using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit.FPS
{
public class Recoil : MonoBehaviour
{
SpringEulerAngle recoilTarget;
public float damp = 20;
public float frequence = 15;
void Awake()
{
recoilTarget = new SpringEulerAngle(damp, frequence);
}
// Update is called once per frame
void FixedUpdate()
{
recoilTarget.Update(Time.deltaTime, Vector3.zero);
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(recoilTarget.value), 0.75f); //这里使用一个较大的插值数字以实现枪口的迅速抬升
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
recoilTarget.value = new Vector3(Random.Range(-20, 0), Random.Range(-3, 3), 0); //这里做一个随机偏移来模拟后坐力。
}
}
}
} */