mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-04 19:09:23 +00:00
Possible to fix for offset on pick up in VR mode
This commit is contained in:
parent
b4a210a546
commit
de463d2236
1 changed files with 15 additions and 13 deletions
|
@ -20,7 +20,7 @@ namespace ml_ppu
|
||||||
|
|
||||||
CapsuleCollider m_collider = null;
|
CapsuleCollider m_collider = null;
|
||||||
Matrix4x4 m_colliderOffSet;
|
Matrix4x4 m_colliderOffSet;
|
||||||
Matrix4x4 m_avatarOffSet;
|
Matrix4x4 m_playerOffSet;
|
||||||
|
|
||||||
Transform m_hips = null;
|
Transform m_hips = null;
|
||||||
Transform m_armLeft = null;
|
Transform m_armLeft = null;
|
||||||
|
@ -104,10 +104,10 @@ namespace ml_ppu
|
||||||
m_collider.transform.position = l_colliderMat.GetPosition();
|
m_collider.transform.position = l_colliderMat.GetPosition();
|
||||||
m_collider.transform.rotation = l_colliderMat.rotation;
|
m_collider.transform.rotation = l_colliderMat.rotation;
|
||||||
|
|
||||||
Matrix4x4 l_avatarMat = l_colliderMat * m_avatarOffSet;
|
Matrix4x4 l_heldMat = l_colliderMat * m_playerOffSet;
|
||||||
BetterBetterCharacterController.Instance.TeleportPlayerTo(l_avatarMat.GetPosition(), l_avatarMat.rotation, true, false); // Extension method with Quaternion as rotation
|
BetterBetterCharacterController.Instance.TeleportPlayerTo(l_heldMat.GetPosition(), l_heldMat.rotation, true, false); // Extension method with Quaternion as rotation
|
||||||
|
|
||||||
Vector3 l_position = l_avatarMat.GetPosition();
|
Vector3 l_position = l_heldMat.GetPosition();
|
||||||
m_velocity = (l_position - m_lastPosition) / Time.deltaTime;
|
m_velocity = (l_position - m_lastPosition) / Time.deltaTime;
|
||||||
m_lastPosition = l_position;
|
m_lastPosition = l_position;
|
||||||
}
|
}
|
||||||
|
@ -140,8 +140,9 @@ namespace ml_ppu
|
||||||
|
|
||||||
if((m_hips != null) && (m_armLeft != null) && (m_armRight != null))
|
if((m_hips != null) && (m_armLeft != null) && (m_armRight != null))
|
||||||
{
|
{
|
||||||
Vector3 l_hipsPos = (PlayerSetup.Instance.transform.GetMatrix().inverse * m_hips.GetMatrix()).GetPosition();
|
Matrix4x4 l_avatarMatInv = PlayerSetup.Instance._avatar.transform.GetMatrix().inverse;
|
||||||
Vector3 l_armPos = (PlayerSetup.Instance.transform.GetMatrix().inverse * m_armLeft.GetMatrix()).GetPosition();
|
Vector3 l_hipsPos = (l_avatarMatInv * m_hips.GetMatrix()).GetPosition();
|
||||||
|
Vector3 l_armPos = (l_avatarMatInv * m_armLeft.GetMatrix()).GetPosition();
|
||||||
|
|
||||||
m_collider = new GameObject("[Collider]").AddComponent<CapsuleCollider>();
|
m_collider = new GameObject("[Collider]").AddComponent<CapsuleCollider>();
|
||||||
m_collider.transform.parent = this.transform;
|
m_collider.transform.parent = this.transform;
|
||||||
|
@ -163,7 +164,7 @@ namespace ml_ppu
|
||||||
|
|
||||||
if(m_collider != null)
|
if(m_collider != null)
|
||||||
{
|
{
|
||||||
UnityEngine.Object.Destroy(m_collider.gameObject);
|
Destroy(m_collider.gameObject);
|
||||||
m_collider = null;
|
m_collider = null;
|
||||||
}
|
}
|
||||||
m_holderPointA = null;
|
m_holderPointA = null;
|
||||||
|
@ -231,18 +232,19 @@ namespace ml_ppu
|
||||||
m_holderPointerB = p_pointer;
|
m_holderPointerB = p_pointer;
|
||||||
|
|
||||||
// Remember offsets
|
// Remember offsets
|
||||||
Quaternion l_avatarRot = PlayerSetup.Instance._avatar.transform.rotation;
|
Vector3 l_playerPos = PlayerSetup.Instance.GetPlayerPosition();
|
||||||
m_holderPointAOffset = Quaternion.Inverse(m_holderPointA.transform.rotation) * l_avatarRot;
|
Quaternion l_playerRot = PlayerSetup.Instance.GetPlayerRotation();
|
||||||
m_holderPointBOffset = Quaternion.Inverse(m_holderPointB.transform.rotation) * l_avatarRot;
|
m_holderPointAOffset = Quaternion.Inverse(m_holderPointA.transform.rotation) * l_playerRot;
|
||||||
|
m_holderPointBOffset = Quaternion.Inverse(m_holderPointB.transform.rotation) * l_playerRot;
|
||||||
|
|
||||||
Matrix4x4 l_midPoint = Matrix4x4.TRS(
|
Matrix4x4 l_midPoint = Matrix4x4.TRS(
|
||||||
Vector3.Lerp(m_holderPointA.transform.position, m_holderPointB.transform.position, 0.5f),
|
Vector3.Lerp(m_holderPointA.transform.position, m_holderPointB.transform.position, 0.5f),
|
||||||
l_avatarRot,
|
l_playerRot,
|
||||||
Vector3.one
|
Vector3.one
|
||||||
);
|
);
|
||||||
m_colliderOffSet = l_midPoint.inverse * m_collider.transform.GetMatrix();
|
m_colliderOffSet = l_midPoint.inverse * m_collider.transform.GetMatrix();
|
||||||
m_avatarOffSet = m_collider.transform.GetMatrix().inverse * PlayerSetup.Instance._avatar.transform.GetMatrix();
|
m_playerOffSet = m_collider.transform.GetMatrix().inverse * Matrix4x4.TRS(l_playerPos, l_playerRot, Vector3.one);
|
||||||
m_lastPosition = PlayerSetup.Instance._avatar.transform.position;
|
m_lastPosition = l_playerPos;
|
||||||
m_velocity = Vector3.zero;
|
m_velocity = Vector3.zero;
|
||||||
m_held = true;
|
m_held = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue