Skip to content

Commit a581e30

Browse files
Fixed arrow model offset from center of projectile object to align it with the origin of collision checks. Moved the isArrow offset code into GetAimPosition method so the arrow still spawns in the same place it did before.
1 parent 1da9ef3 commit a581e30

1 file changed

Lines changed: 26 additions & 20 deletions

File tree

Assets/Scripts/Game/DaggerfallMissile.cs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -211,26 +211,7 @@ private void Start()
211211
// Create and orient 3d arrow
212212
goModel = GameObjectHelper.CreateDaggerfallMeshGameObject(99800, transform, ignoreCollider: true);
213213

214-
// Offset up so it comes from same place LOS check is done from
215-
Vector3 adjust;
216-
if (caster != GameManager.Instance.PlayerEntityBehaviour)
217-
{
218-
CharacterController controller = caster.transform.GetComponent<CharacterController>();
219-
adjust = caster.transform.forward * 0.6f;
220-
adjust.y += controller.height / 3;
221-
}
222-
else
223-
{
224-
// Adjust slightly downward to match bow animation
225-
adjust = (GameManager.Instance.MainCamera.transform.rotation * -Caster.transform.up) * 0.11f;
226-
// Adjust to the right or left to match bow animation
227-
if (!GameManager.Instance.WeaponManager.ScreenWeapon.FlipHorizontal)
228-
adjust += GameManager.Instance.MainCamera.transform.right * 0.15f;
229-
else
230-
adjust -= GameManager.Instance.MainCamera.transform.right * 0.15f;
231-
}
232-
233-
goModel.transform.localPosition = adjust;
214+
goModel.transform.localPosition = Vector3.zero;
234215
goModel.transform.rotation = Quaternion.LookRotation(GetAimDirection());
235216
goModel.layer = gameObject.layer;
236217
}
@@ -332,6 +313,7 @@ private void FixedUpdate()
332313
castFoundHit = Physics.Raycast(colliderPosition, direction, out hitInfo, displacement.magnitude + ColliderRadius, layerMask);
333314
else
334315
castFoundHit = Physics.SphereCast(colliderPosition, ColliderRadius, direction, out hitInfo, displacement.magnitude + ColliderRadius, layerMask);
316+
335317
if (castFoundHit)
336318
{
337319
// Place self at meeting point with collider and do collision logic.
@@ -498,6 +480,30 @@ Vector3 GetAimPosition()
498480
aimPosition = GameManager.Instance.MainCamera.transform.position;
499481
}
500482

483+
//projectile offset code moved here for accuracy
484+
if (isArrow)
485+
{
486+
// Offset up so it comes from same place LOS check is done from
487+
Vector3 adjust;
488+
if (caster != GameManager.Instance.PlayerEntityBehaviour)
489+
{
490+
CharacterController controller = caster.transform.GetComponent<CharacterController>();
491+
adjust = caster.transform.forward * 0.6f;
492+
adjust.y += controller.height / 3;
493+
}
494+
else
495+
{
496+
// Adjust slightly downward to match bow animation
497+
adjust = (GameManager.Instance.MainCamera.transform.rotation * -Caster.transform.up) * 0.11f;
498+
// Adjust to the right or left to match bow animation
499+
if (!GameManager.Instance.WeaponManager.ScreenWeapon.FlipHorizontal)
500+
adjust += GameManager.Instance.MainCamera.transform.right * 0.15f;
501+
else
502+
adjust -= GameManager.Instance.MainCamera.transform.right * 0.15f;
503+
}
504+
aimPosition += adjust;
505+
}
506+
501507
return aimPosition;
502508
}
503509

0 commit comments

Comments
 (0)