Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Assets/SteamVR/Extras/SteamVR_TestThrow.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//======= Copyright (c) Valve Corporation, All rights reserved. ===============
using UnityEngine;
using System.Collections;

namespace Valve.VR.Extras
{
Expand Down Expand Up @@ -46,12 +45,20 @@ private void FixedUpdate()
Transform origin = trackedObj.origin ? trackedObj.origin : trackedObj.transform.parent;
if (origin != null)
{
#if UNITY_6000_0_OR_NEWER
rigidbody.linearVelocity = origin.TransformVector(trackedObj.GetVelocity());
#else
rigidbody.velocity = origin.TransformVector(trackedObj.GetVelocity());
#endif
rigidbody.angularVelocity = origin.TransformVector(trackedObj.GetAngularVelocity());
}
else
{
#if UNITY_6000_0_OR_NEWER
rigidbody.linearVelocity = trackedObj.GetVelocity();
#else
rigidbody.velocity = trackedObj.GetVelocity();
#endif
rigidbody.angularVelocity = trackedObj.GetAngularVelocity();
}

Expand Down
9 changes: 8 additions & 1 deletion Assets/SteamVR/InteractionSystem/Core/Scripts/Hand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine.Events;
using System.Threading;

namespace Valve.VR.InteractionSystem
{
Expand Down Expand Up @@ -1233,7 +1232,11 @@ protected virtual void FixedUpdate()
{
if (attachedInfo.HasAttachFlag(AttachmentFlags.VelocityMovement))
{
#if UNITY_6000_0_OR_NEWER
attachedInfo.attachedRigidbody.linearVelocity = Vector3.zero;
#else
attachedInfo.attachedRigidbody.velocity = Vector3.zero;
#endif
attachedInfo.attachedRigidbody.angularVelocity = Vector3.zero;
}
t = attachedInfo.interactable.snapAttachEaseInCurve.Evaluate(t);
Expand Down Expand Up @@ -1265,7 +1268,11 @@ protected void UpdateAttachedVelocity(AttachedObject attachedObjectInfo)
float maxAngularVelocityChange = MaxAngularVelocityChange * scale;
float maxVelocityChange = MaxVelocityChange * scale;

#if UNITY_6000_0_OR_NEWER
attachedObjectInfo.attachedRigidbody.linearVelocity = Vector3.MoveTowards(attachedObjectInfo.attachedRigidbody.linearVelocity, velocityTarget, maxVelocityChange);
#else
attachedObjectInfo.attachedRigidbody.velocity = Vector3.MoveTowards(attachedObjectInfo.attachedRigidbody.velocity, velocityTarget, maxVelocityChange);
#endif
attachedObjectInfo.attachedRigidbody.angularVelocity = Vector3.MoveTowards(attachedObjectInfo.attachedRigidbody.angularVelocity, angularTarget, maxAngularVelocityChange);
}
}
Expand Down
37 changes: 35 additions & 2 deletions Assets/SteamVR/InteractionSystem/Core/Scripts/HandCollider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Valve.VR.InteractionSystem
Expand Down Expand Up @@ -71,8 +69,13 @@ public Transform[] this[int finger]

}

#if UNITY_6000_0_OR_NEWER
private static PhysicsMaterial physicMaterial_lowfriction;
private static PhysicsMaterial physicMaterial_highfriction;
#else
private static PhysicMaterial physicMaterial_lowfriction;
private static PhysicMaterial physicMaterial_highfriction;
#endif

private void Awake()
{
Expand All @@ -86,30 +89,52 @@ private void Start()

if (physicMaterial_lowfriction == null)
{
#if UNITY_6000_0_OR_NEWER
physicMaterial_lowfriction = new PhysicsMaterial("hand_lowFriction");
#else
physicMaterial_lowfriction = new PhysicMaterial("hand_lowFriction");
#endif
physicMaterial_lowfriction.dynamicFriction = 0;
physicMaterial_lowfriction.staticFriction = 0;
physicMaterial_lowfriction.bounciness = 0;
#if UNITY_6000_0_OR_NEWER
physicMaterial_lowfriction.bounceCombine = PhysicsMaterialCombine.Minimum;
physicMaterial_lowfriction.frictionCombine = PhysicsMaterialCombine.Minimum;
#else
physicMaterial_lowfriction.bounceCombine = PhysicMaterialCombine.Minimum;
physicMaterial_lowfriction.frictionCombine = PhysicMaterialCombine.Minimum;
#endif
}

if (physicMaterial_highfriction == null)
{
#if UNITY_6000_0_OR_NEWER
physicMaterial_highfriction = new PhysicsMaterial("hand_highFriction");
#else
physicMaterial_highfriction = new PhysicMaterial("hand_highFriction");
#endif
physicMaterial_highfriction.dynamicFriction = 1f;
physicMaterial_highfriction.staticFriction = 1f;
physicMaterial_highfriction.bounciness = 0;
#if UNITY_6000_0_OR_NEWER
physicMaterial_highfriction.bounceCombine = PhysicsMaterialCombine.Minimum;
physicMaterial_highfriction.frictionCombine = PhysicsMaterialCombine.Average;
#else
physicMaterial_highfriction.bounceCombine = PhysicMaterialCombine.Minimum;
physicMaterial_highfriction.frictionCombine = PhysicMaterialCombine.Average;
#endif
}

SetPhysicMaterial(physicMaterial_lowfriction);

scale = SteamVR_Utils.GetLossyScale(hand.transform);
}

#if UNITY_6000_0_OR_NEWER
void SetPhysicMaterial(PhysicsMaterial mat)
#else
void SetPhysicMaterial(PhysicMaterial mat)
#endif
{
if (colliders == null) colliders = GetComponentsInChildren<Collider>();
for (int i = 0; i < colliders.Length; i++)
Expand Down Expand Up @@ -179,7 +204,11 @@ protected void ExecuteFixedUpdate()
if (collidersInRadius == false)
{
//keep updating velocity, just in case. Otherwise you get jitter
#if UNITY_6000_0_OR_NEWER
rigidbody.linearVelocity = Vector3.zero;
#else
rigidbody.velocity = Vector3.zero;
#endif
rigidbody.angularVelocity = Vector3.zero;
/*
rigidbody.velocity = (targetPosition - rigidbody.position) / Time.fixedDeltaTime;
Expand All @@ -200,7 +229,11 @@ protected void ExecuteFixedUpdate()
float maxAngularVelocityChange = MaxAngularVelocityChange * scale;
float maxVelocityChange = MaxVelocityChange * scale;

#if UNITY_6000_0_OR_NEWER
rigidbody.linearVelocity = Vector3.MoveTowards(rigidbody.linearVelocity, velocityTarget, maxVelocityChange);
#else
rigidbody.velocity = Vector3.MoveTowards(rigidbody.velocity, velocityTarget, maxVelocityChange);
#endif
rigidbody.angularVelocity = Vector3.MoveTowards(rigidbody.angularVelocity, angularTarget, maxAngularVelocityChange);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
//=============================================================================

using UnityEngine;
using UnityEngine.Events;
using System.Collections;
using System.Collections.Generic;

namespace Valve.VR.InteractionSystem
Expand Down Expand Up @@ -155,7 +153,11 @@ private InteractableDebug CreateSimulation(Hand fromHand, float timeOffset, Colo
Vector3 velocity = fromHand.GetTrackedObjectVelocity(timeOffset);
velocity *= throwable.scaleReleaseVelocity;

#if UNITY_6000_0_OR_NEWER
debugCopy.rigidbody.linearVelocity = velocity;
#else
debugCopy.rigidbody.velocity = velocity;
#endif

return debugCopy;
}
Expand Down
18 changes: 17 additions & 1 deletion Assets/SteamVR/InteractionSystem/Core/Scripts/Throwable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ protected virtual void OnHandHoverBegin( Hand hand )

if ( bestGrabType != GrabTypes.None )
{
#if UNITY_6000_0_OR_NEWER
if (rigidbody.linearVelocity.magnitude >= catchingThreshold)
#else
if (rigidbody.velocity.magnitude >= catchingThreshold)
{
#endif
{
hand.AttachObject( gameObject, bestGrabType, attachmentFlags );
showHint = false;
}
Expand Down Expand Up @@ -174,7 +178,11 @@ protected virtual void OnDetachedFromHand(Hand hand)

GetReleaseVelocities(hand, out velocity, out angularVelocity);

#if UNITY_6000_0_OR_NEWER
rigidbody.linearVelocity = velocity;
#else
rigidbody.velocity = velocity;
#endif
rigidbody.angularVelocity = angularVelocity;
}

Expand All @@ -197,7 +205,11 @@ public virtual void GetReleaseVelocities(Hand hand, out Vector3 velocity, out Ve
{
Debug.LogWarning("[SteamVR Interaction System] Throwable: No Velocity Estimator component on object but release style set to short estimation. Please add one or change the release style.");

#if UNITY_6000_0_OR_NEWER
velocity = rigidbody.linearVelocity;
#else
velocity = rigidbody.velocity;
#endif
angularVelocity = rigidbody.angularVelocity;
}
break;
Expand All @@ -210,7 +222,11 @@ public virtual void GetReleaseVelocities(Hand hand, out Vector3 velocity, out Ve
break;
default:
case ReleaseStyle.NoChange:
#if UNITY_6000_0_OR_NEWER
velocity = rigidbody.linearVelocity;
#else
velocity = rigidbody.velocity;
#endif
angularVelocity = rigidbody.angularVelocity;
break;
}
Expand Down
61 changes: 52 additions & 9 deletions Assets/SteamVR/InteractionSystem/Longbow/Scripts/Arrow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//=============================================================================

using UnityEngine;
using System.Collections;

namespace Valve.VR.InteractionSystem
{
Expand All @@ -16,9 +15,13 @@ public class Arrow : MonoBehaviour
public Rigidbody arrowHeadRB;
public Rigidbody shaftRB;

#if UNITY_6000_0_OR_NEWER
public PhysicsMaterial targetPhysMaterial;
#else
public PhysicMaterial targetPhysMaterial;
#endif

private Vector3 prevPosition;
private Vector3 prevPosition;
private Quaternion prevRotation;
private Vector3 prevVelocity;
private Vector3 prevHeadPosition;
Expand Down Expand Up @@ -48,8 +51,13 @@ public class Arrow : MonoBehaviour
private void Awake()
{
initialMass = shaftRB.mass;
#if UNITY_6000_0_OR_NEWER
initialDrag = shaftRB.linearDamping;
initialAngularDrag = shaftRB.angularDamping;
#else
initialDrag = shaftRB.drag;
initialAngularDrag = shaftRB.angularDrag;
#endif
initialInterpolation = shaftRB.interpolation;
initialCollisionDetection = shaftRB.collisionDetectionMode;
initialUseGravity = shaftRB.useGravity;
Expand All @@ -70,8 +78,12 @@ void FixedUpdate()
{
prevPosition = transform.position;
prevRotation = transform.rotation;
#if UNITY_6000_0_OR_NEWER
prevVelocity = shaftRB.linearVelocity;
#else
prevVelocity = shaftRB.velocity;
prevHeadPosition = arrowHeadRB.transform.position;
#endif
prevHeadPosition = arrowHeadRB.transform.position;
travelledFrames++;
}
}
Expand All @@ -85,9 +97,14 @@ public void StartRelease()
shaftRB = rb;

shaftRB.mass = initialMass;
#if UNITY_6000_0_OR_NEWER
shaftRB.linearDamping = initialDrag;
shaftRB.angularDamping = initialAngularDrag;
#else
shaftRB.drag = initialDrag;
shaftRB.angularDrag = initialAngularDrag;
shaftRB.interpolation = initialInterpolation;
#endif
shaftRB.interpolation = initialInterpolation;
shaftRB.collisionDetectionMode = initialCollisionDetection;
shaftRB.useGravity = initialUseGravity;

Expand Down Expand Up @@ -128,7 +145,11 @@ public void ArrowReleased( float inputVelocity )
prevPosition = transform.position;
prevRotation = transform.rotation;
prevHeadPosition = arrowHeadRB.transform.position;
#if UNITY_6000_0_OR_NEWER
prevVelocity = GetComponent<Rigidbody>().linearVelocity;
#else
prevVelocity = GetComponent<Rigidbody>().velocity;
#endif

SetCollisionMode(CollisionDetectionMode.ContinuousDynamic);

Expand All @@ -152,8 +173,12 @@ void OnCollisionEnter( Collision collision )
if ( inFlight )
{
Rigidbody rb = GetComponent<Rigidbody>();
#if UNITY_6000_0_OR_NEWER
float rbSpeed = rb.linearVelocity.sqrMagnitude;
#else
float rbSpeed = rb.velocity.sqrMagnitude;
bool canStick = ( targetPhysMaterial != null && collision.collider.sharedMaterial == targetPhysMaterial && rbSpeed > 0.2f );
#endif
bool canStick = ( targetPhysMaterial != null && collision.collider.sharedMaterial == targetPhysMaterial && rbSpeed > 0.2f );
bool hitBalloon = collision.collider.gameObject.GetComponent<Balloon>() != null;

if ( travelledFrames < 2 && !canStick )
Expand All @@ -162,11 +187,17 @@ void OnCollisionEnter( Collision collision )
transform.position = prevPosition - prevVelocity * Time.deltaTime;
transform.rotation = prevRotation;

#if UNITY_6000_0_OR_NEWER
Vector3 reflfectDir = Vector3.Reflect(arrowHeadRB.linearVelocity, collision.contacts[0].normal);
arrowHeadRB.linearVelocity = reflfectDir * 0.25f;
shaftRB.linearVelocity = reflfectDir * 0.25f;
#else
Vector3 reflfectDir = Vector3.Reflect( arrowHeadRB.velocity, collision.contacts[0].normal );
arrowHeadRB.velocity = reflfectDir * 0.25f;
shaftRB.velocity = reflfectDir * 0.25f;
#endif

travelledFrames = 0;
travelledFrames = 0;
return;
}

Expand Down Expand Up @@ -208,8 +239,12 @@ void OnCollisionEnter( Collision collision )
// Revert my physics properties cause I don't want balloons to influence my travel
transform.position = prevPosition;
transform.rotation = prevRotation;
#if UNITY_6000_0_OR_NEWER
arrowHeadRB.linearVelocity = prevVelocity;
#else
arrowHeadRB.velocity = prevVelocity;
Physics.IgnoreCollision( arrowHeadRB.GetComponent<Collider>(), collision.collider );
#endif
Physics.IgnoreCollision( arrowHeadRB.GetComponent<Collider>(), collision.collider );
Physics.IgnoreCollision( shaftRB.GetComponent<Collider>(), collision.collider );
}

Expand Down Expand Up @@ -261,14 +296,22 @@ private void StickInTarget( Collision collision, bool bSkipRayCast )

SetCollisionMode(CollisionDetectionMode.Discrete, true);

#if UNITY_6000_0_OR_NEWER
shaftRB.linearVelocity = Vector3.zero;
#else
shaftRB.velocity = Vector3.zero;
shaftRB.angularVelocity = Vector3.zero;
#endif
shaftRB.angularVelocity = Vector3.zero;
shaftRB.isKinematic = true;
shaftRB.useGravity = false;
shaftRB.transform.GetComponent<BoxCollider>().enabled = false;

#if UNITY_6000_0_OR_NEWER
arrowHeadRB.linearVelocity = Vector3.zero;
#else
arrowHeadRB.velocity = Vector3.zero;
arrowHeadRB.angularVelocity = Vector3.zero;
#endif
arrowHeadRB.angularVelocity = Vector3.zero;
arrowHeadRB.isKinematic = true;
arrowHeadRB.useGravity = false;
arrowHeadRB.transform.GetComponent<BoxCollider>().enabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,12 @@ private void FireArrow()
arrow.arrowHeadRB.AddForce( currentArrow.transform.forward * bow.GetArrowVelocity(), ForceMode.VelocityChange );
arrow.arrowHeadRB.AddTorque( currentArrow.transform.forward * 10 );

#if UNITY_6000_0_OR_NEWER
arrow.shaftRB.linearVelocity = arrow.arrowHeadRB.linearVelocity;
#else
arrow.shaftRB.velocity = arrow.arrowHeadRB.velocity;
arrow.shaftRB.angularVelocity = arrow.arrowHeadRB.angularVelocity;
#endif
arrow.shaftRB.angularVelocity = arrow.arrowHeadRB.angularVelocity;

nocked = false;
nockedWithType = GrabTypes.None;
Expand Down
Loading