Here are the examples of the csharp api Cinemachine.CinemachineCollider.GetWalkingDirection(UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.RaycastHit, ref UnityEngine.Vector3) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
19
View Source File : CinemachineCollider.cs
License : MIT License
Project Creator : BattleDawnNZ
License : MIT License
Project Creator : BattleDawnNZ
private Vector3 PushCameraBack(
Vector3 currentPos, Vector3 pushDir, RaycastHit obstacle,
Vector3 lookAtPos, Plane startPlane, float targetDistance, int iterations,
ref VcamExtraState extra)
{
// Take a step along the wall.
Vector3 pos = currentPos;
Vector3 dir = Vector3.zero;
if (!GetWalkingDirection(pos, pushDir, obstacle, ref dir))
return pos;
Ray ray = new Ray(pos, dir);
float distance = GetPushBackDistance(ray, startPlane, targetDistance, lookAtPos);
if (distance <= Epsilon)
return pos;
// Check only as far as the obstacle bounds
float clampedDistance = ClampRayToBounds(ray, distance, obstacle.collider.bounds);
distance = Mathf.Min(distance, clampedDistance + PrecisionSlush);
RaycastHit hitInfo;
if (RaycastIgnoreTag(ray, out hitInfo, distance,
m_CollideAgainst & ~m_TransparentLayers))
{
// We hit something. Stop there and take a step along that wall.
float adjustment = hitInfo.distance - PrecisionSlush;
pos = ray.GetPoint(adjustment);
extra.AddPointToDebugPath(pos);
if (iterations > 1)
pos = PushCameraBack(
pos, dir, hitInfo,
lookAtPos, startPlane,
targetDistance, iterations-1, ref extra);
return pos;
}
// Didn't hit anything. Can we push back all the way now?
pos = ray.GetPoint(distance);
// First check if we can still see the target. If not, abort
dir = pos - lookAtPos;
float d = dir.magnitude;
RaycastHit hitInfo2;
if (d < Epsilon || RaycastIgnoreTag(
new Ray(lookAtPos, dir), out hitInfo2, d - PrecisionSlush,
m_CollideAgainst & ~m_TransparentLayers))
return currentPos;
// All clear
ray = new Ray(pos, dir);
extra.AddPointToDebugPath(pos);
distance = GetPushBackDistance(ray, startPlane, targetDistance, lookAtPos);
if (distance > Epsilon)
{
if (!RaycastIgnoreTag(ray, out hitInfo, distance,
m_CollideAgainst & ~m_TransparentLayers))
{
pos = ray.GetPoint(distance); // no obstacles - all good
extra.AddPointToDebugPath(pos);
}
else
{
// We hit something. Stop there and maybe take a step along that wall
float adjustment = hitInfo.distance - PrecisionSlush;
pos = ray.GetPoint(adjustment);
extra.AddPointToDebugPath(pos);
if (iterations > 1)
pos = PushCameraBack(
pos, dir, hitInfo, lookAtPos, startPlane,
targetDistance, iterations-1, ref extra);
}
}
return pos;
}
19
View Source File : CinemachineCollider.cs
License : MIT License
Project Creator : PacktPublishing
License : MIT License
Project Creator : PacktPublishing
private Vector3 PushCameraBack(
Vector3 currentPos, Vector3 pushDir, RaycastHit obstacle,
Vector3 lookAtPos, Plane startPlane, float targetDistance, int iterations,
ref VcamExtraState extra)
{
// Take a step along the wall.
Vector3 pos = currentPos;
Vector3 dir = Vector3.zero;
if (!GetWalkingDirection(pos, pushDir, obstacle, ref dir))
return pos;
Ray ray = new Ray(pos, dir);
float distance = GetPushBackDistance(ray, startPlane, targetDistance, lookAtPos);
if (distance <= Epsilon)
return pos;
// Check only as far as the obstacle bounds
float clampedDistance = ClampRayToBounds(ray, distance, obstacle.collider.bounds);
distance = Mathf.Min(distance, clampedDistance + PrecisionSlush);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, distance, m_CollideAgainst.value))
{
// We hit something. Stop there and take a step along that wall.
float adjustment = hitInfo.distance - PrecisionSlush;
pos = ray.GetPoint(adjustment);
extra.AddPointToDebugPath(pos);
if (iterations > 1)
pos = PushCameraBack(
pos, dir, hitInfo,
lookAtPos, startPlane,
targetDistance, iterations-1, ref extra);
return pos;
}
// Didn't hit anything. Can we push back all the way now?
pos = ray.GetPoint(distance);
// First check if we can still see the target. If not, abort
dir = pos - lookAtPos;
float d = dir.magnitude;
RaycastHit hitInfo2;
if (d < Epsilon || Physics.Raycast(
new Ray(lookAtPos, dir), out hitInfo2, d - PrecisionSlush, m_CollideAgainst.value,
QueryTriggerInteraction.Ignore))
{
return currentPos;
}
// All clear
ray = new Ray(pos, dir);
extra.AddPointToDebugPath(pos);
distance = GetPushBackDistance(ray, startPlane, targetDistance, lookAtPos);
if (distance > Epsilon)
{
if (!Physics.Raycast(
ray, out hitInfo, distance, m_CollideAgainst.value,
QueryTriggerInteraction.Ignore))
{
pos = ray.GetPoint(distance); // no obstacles - all good
extra.AddPointToDebugPath(pos);
}
else
{
// We hit something. Stop there and maybe take a step along that wall
float adjustment = hitInfo.distance - PrecisionSlush;
pos = ray.GetPoint(adjustment);
extra.AddPointToDebugPath(pos);
if (iterations > 1)
pos = PushCameraBack(
pos, dir, hitInfo, lookAtPos, startPlane,
targetDistance, iterations-1, ref extra);
}
}
return pos;
}