Question by
Niilay · Nov 14, 2019 at 12:23 AM ·
shootinglinerenderer
How can I make a Raycast work with isometric angles?
Im having problems aligning the mouse position with the raycast. The camera is orthographic, set at angles (30, 45, 0). The raycast is slightly offset when rotating.
Example:
Code for Raycast:
void Shoot ()
{
timer = 0f;
gunAudio.Play ();
gunLight.enabled = true;
gunParticles.Stop ();
gunParticles.Play ();
gunLine.enabled = true;
gunLine.SetPosition (0, transform.position);
shootRay.origin = transform.position;
shootRay.direction = transform.forward;
if(Physics.Raycast (shootRay, out shootHit, range, shootableMask))
{
EnemyHealth enemyHealth = shootHit.collider.GetComponent<EnemyHealth>();
if(enemyHealth != null)
{
enemyHealth.TakeDamage (damagePerShot, shootHit.point);
}
gunLine.SetPosition (1, shootHit.point);
}
else
{
gunLine.SetPosition (1, shootRay.origin + shootRay.direction * range);
}
}
}
Code for rotation:
void Turning()
{
Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit floorHit;
if (Physics.Raycast(camRay, out floorHit, camRayLength, floorMask))
{
Vector3 playerToMouse = new Vector3(floorHit.point.x, transform.position.y, floorHit.point.z);
transform.LookAt(playerToMouse);
}
}
example.jpg
(111.4 kB)
Comment