My RayCast isn't facing forward
Currently there is a script which references the position of an invisible GameObject at the front of the muzzle, and draws a ray from its position. It's supposed to draw it forward, but for some reason when I execute my code:
private GameObject muzzle;
void Start () {
muzzle = GameObject.Find("pistol_BulletSpawner");
}
void Update {
Debug.DrawLine(muzzle.transform.position,
muzzle.transform.TransformDirection(Vector3.forward), Color.blue);
}
It points down and to the right, like this:
Answer by Sigillimus · Apr 27, 2016 at 03:31 AM
Kind of solved my own issue. Apparently Debug.DrawLine doesn't operate in the same way that Debug.DrawRay does - which seems obvious, but I didn't think of it at the time. That being said, I've found that using '.TransformDirection(Vector3.forward)' with Debug.DrawRay points to the right, rather than forward. I had to use Vector3.left instead, which seems to work - still not sure what's causing that.
Your answer
Follow this Question
Related Questions
My raycasting isn't working 1 Answer
Find Normal Vector to BoxCollider 0 Answers
Why is my logic happening 9 times? 0 Answers
What can I do to get Unity to understand the Debug.Drawline command? 1 Answer