NEW HVR 2.9.1f
This commit is contained in:
+24
-16
@@ -62,6 +62,10 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
private Transform _grabbedPositionTracker;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The offset of the cocking handle when it's grabbed
|
||||
/// </summary>
|
||||
protected float GrabOffset { get; set; }
|
||||
|
||||
public bool EmptyOpen { get; protected set; }
|
||||
|
||||
@@ -160,27 +164,27 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
return;
|
||||
}
|
||||
|
||||
var pullDirection = (Grabbable.HandGrabbers[0].TrackedController.position - _grabbedPositionTracker.transform.position);
|
||||
var pullDirection = (Grabbable.HandGrabbers[0].TrackedController.position - _grabbedPositionTracker.position);
|
||||
var backDirection = (MaxPositionWorld - ForwardPositionWorld).normalized * 10;
|
||||
var amount = Vector3.Dot(pullDirection, backDirection);
|
||||
var amount = Vector3.Dot(pullDirection, backDirection) * Difficulty;
|
||||
|
||||
if (amount > 0)
|
||||
if (amount + GrabOffset > 0)
|
||||
{
|
||||
UpdatePosition(amount);
|
||||
|
||||
var distance = Vector3.Distance(transform.position, ForwardPositionWorld);
|
||||
|
||||
CheckEject(distance);
|
||||
CheckChamberDistance(distance);
|
||||
ClampPullBack(distance, BackDirectionWorld);
|
||||
MoveBolt();
|
||||
AnimateParts();
|
||||
CheckLock(distance);
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.localPosition = ForwardPosition;
|
||||
}
|
||||
|
||||
var distance = Vector3.Distance(transform.position, ForwardPositionWorld);
|
||||
|
||||
CheckEject(distance);
|
||||
CheckChamberDistance(distance);
|
||||
ClampPullBack(distance, BackDirectionWorld);
|
||||
MoveBolt();
|
||||
AnimateParts();
|
||||
CheckLock(distance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,8 +206,7 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
|
||||
private void UpdatePosition(float amount)
|
||||
{
|
||||
|
||||
transform.position = ForwardPositionWorld + BackDirectionWorld * (amount * Difficulty);
|
||||
transform.position = ForwardPositionWorld + BackDirectionWorld * (amount + GrabOffset);
|
||||
}
|
||||
|
||||
|
||||
@@ -337,6 +340,8 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
|
||||
protected virtual void OnGrabbed(HVRHandGrabber grabber, HVRGrabbable slide)
|
||||
{
|
||||
GrabOffset = 0f;
|
||||
|
||||
if (ImmediateReleaseWhenOpen && EmptyOpen && LocksBack)
|
||||
{
|
||||
if (Bolt)
|
||||
@@ -350,14 +355,17 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
_previousVelocity = Vector3.zero;
|
||||
if (Type == HVRCockingHandleType.Pump)
|
||||
{
|
||||
_grabbedPositionTracker.transform.position = grabber.GrabPoint.position;
|
||||
_grabbedPositionTracker.position = grabber.GrabPoint.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
_grabbedPositionTracker.transform.localPosition = transform.parent.InverseTransformPoint(_previousHandPosition);
|
||||
_grabbedPositionTracker.localPosition = transform.parent.InverseTransformPoint(_previousHandPosition);
|
||||
GrabOffset = Vector3.Distance(ForwardPositionWorld, transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected virtual void OnReleased(HVRHandGrabber grabber, HVRGrabbable slide)
|
||||
{
|
||||
EmptyOpen = false;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HurricaneVR.Framework.Components;
|
||||
@@ -36,7 +37,7 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
|
||||
[Tooltip("Is chambering required to shoot")]
|
||||
public bool RequiresChamberedBullet = true;
|
||||
public FireType FireType = FireType.Single;
|
||||
public GunFireType FireType = GunFireType.Single;
|
||||
|
||||
[Tooltip("Speed of the bullet prefab")]
|
||||
public float BulletSpeed = 40f;
|
||||
@@ -126,7 +127,7 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
private Coroutine _animationRoutine;
|
||||
|
||||
public UnityEvent Fired = new UnityEvent();
|
||||
public GunHitEvent Hit = new GunHitEvent();
|
||||
public HVRGunHitEvent Hit = new HVRGunHitEvent();
|
||||
|
||||
protected float TimeOfLastShot { get; set; }
|
||||
|
||||
@@ -554,7 +555,7 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
return;
|
||||
}
|
||||
|
||||
if (FireType == FireType.Single)
|
||||
if (FireType == GunFireType.Single)
|
||||
{
|
||||
if (Time.time - TimeOfLastShot < Cooldown)
|
||||
return;
|
||||
@@ -565,7 +566,7 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsFiring && FireType == FireType.ThreeRoundBurst)
|
||||
if (IsFiring && FireType == GunFireType.ThreeRoundBurst)
|
||||
return;
|
||||
|
||||
IsFiring = true;
|
||||
@@ -574,7 +575,7 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
|
||||
public virtual void TriggerReleased()
|
||||
{
|
||||
if (FireType == FireType.Automatic)
|
||||
if (FireType == GunFireType.Automatic)
|
||||
{
|
||||
IsFiring = false;
|
||||
}
|
||||
@@ -602,7 +603,7 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
PlayHaptics(Grabbable, Haptics.DryFire);
|
||||
}
|
||||
|
||||
public virtual void UpdateTrackedBullets()
|
||||
private void UpdateTrackedBullets()
|
||||
{
|
||||
for (int i = 0; i < _objects.Count; i++)
|
||||
{
|
||||
@@ -615,7 +616,7 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
|
||||
if (Physics.Raycast(bullet.transform.position, tracker.Direction, out var hit, distance, HitLayerMask, QueryTriggerInteraction.Ignore))
|
||||
{
|
||||
OnHit(bullet, hit, tracker.Direction);
|
||||
OnHit(hit, tracker.Direction);
|
||||
bullet.SetActive(false);
|
||||
_objects[i].SetRenderersActive(false);
|
||||
}
|
||||
@@ -708,7 +709,7 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
TimeOfLastShot = Time.time;
|
||||
RoundsFired++;
|
||||
|
||||
if (FireType == FireType.ThreeRoundBurst && RoundsFired == 3)
|
||||
if (FireType == GunFireType.ThreeRoundBurst && RoundsFired == 3)
|
||||
{
|
||||
IsFiring = false;
|
||||
}
|
||||
@@ -1005,7 +1006,7 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
}
|
||||
|
||||
|
||||
protected virtual void OnHit(GameObject bullet, RaycastHit hit, Vector3 direction)
|
||||
protected virtual void OnHit(RaycastHit hit, Vector3 direction)
|
||||
{
|
||||
var damageHandler = hit.collider.GetComponent<HVRDamageHandlerBase>();
|
||||
if (damageHandler)
|
||||
@@ -1020,7 +1021,7 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
hit.collider.attachedRigidbody.AddForceAtPosition(direction.normalized * Force, hit.point, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
Hit.Invoke(damageHandler);
|
||||
Hit.Invoke(new GunHitArgs(this, direction, hit));
|
||||
}
|
||||
|
||||
public virtual void EjectBullet()
|
||||
@@ -1126,4 +1127,39 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class HVRGunHitEvent : UnityEvent<GunHitArgs>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public struct GunHitArgs
|
||||
{
|
||||
public HVRGunBase Gun;
|
||||
public Vector3 HitPoint;
|
||||
public Vector3 Normal;
|
||||
public Vector3 Direction;
|
||||
public Collider Collider;
|
||||
public Rigidbody Rb;
|
||||
public float Distance;
|
||||
|
||||
public GunHitArgs(HVRGunBase gun, Vector3 direction, RaycastHit hit)
|
||||
{
|
||||
Gun = gun;
|
||||
HitPoint = hit.point;
|
||||
Normal = hit.normal;
|
||||
Direction = direction;
|
||||
Collider = hit.collider;
|
||||
Rb = hit.collider.attachedRigidbody;
|
||||
Distance = hit.distance;
|
||||
}
|
||||
}
|
||||
|
||||
public enum GunFireType
|
||||
{
|
||||
Single,
|
||||
ThreeRoundBurst,
|
||||
Automatic
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using UnityEngine;
|
||||
using HurricaneVR.Framework.Core;
|
||||
using HurricaneVR.Framework.Core.Grabbers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HurricaneVR.Framework.Weapons.Guns
|
||||
{
|
||||
@@ -32,5 +34,15 @@ namespace HurricaneVR.Framework.Weapons.Guns
|
||||
EjectCasing();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAmmoSocketed(HVRGrabberBase grabber, HVRGrabbable grabbable)
|
||||
{
|
||||
AmmoSocketedHaptics();
|
||||
}
|
||||
|
||||
protected override void OnAmmoSocketReleased(HVRGrabberBase arg0, HVRGrabbable arg1)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user