Hi, I’m trying to allign my “spawn projectile point” to where my mouse cursor is, but I’m having a bit of a problem. As you can see in the image, it has a slight offset.
I’ve set my player right hand IK to 1 already and I’m setting it to aim towards that silver sphere (that is my cursor position)
private void OnAnimatorIK()
{
// Weapon aim at target IK
animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1f);
animator.SetIKPosition(AvatarIKGoal.RightHand, aimTarget.position);
}
The thing is that as you can see in the picture, the z-axis of my spawn point is a bit off.
I have the code in the player to fire the bullet and pass the bulletSpawnPoint (that is a transform I have parented to the player bones to indicate where I want the bullet to spawn from) as an Euler Angle:
private void Fire()
{
var go = Instantiate(bulletPrefab);
go.transform.position = bulletSpawnPoint.position;
var bullet = go.GetComponent<Bullet>();
bullet.Fire(go.transform.position, bulletSpawnPoint.eulerAngles + aimTargetOffset, gameObject.layer);
}
And lastly I have a script in the bullet that tells it to move forward based on the parameters I’ve set
public void Fire(Vector3 position, Vector3 euler, int layer)
{
transform.position = position;
transform.eulerAngles = euler;
transform.position = new Vector3(transform.position.x, transform.position.y, 0f);
transform.rotation = Quaternion.LookRotation(transform.forward, Vector3.forward);
}
void Update()
{
transform.Translate(Vector3.forward * velocity * Time.deltaTime);
}
Does anyone have any ideas?
Thank you