Problems with Raycasting (I've never used it before)
I've been using Unity for a little while now, but in the times I've been able to figure things out myself I'm incredibly confused. I spent an entire day on the weekend trying to figure out what was wrong, and it wasn't working. The problem isn't as complex as you'd think:
Debug.DrawRay(player.transform.position + offset, transform.TransformDirection(originalObject.transform.forward), Color.black);
originalObject is being set to lookAt the player every frame, and "player.transform.position + offset" is the same thing that the camera's position is set to. But when I look at which direction the ray is going, it is going completely in the wrong direction. I have no idea why this is happening, please help me!
This is unity 2019.1.10f1 btw, if it's a glitch or something. The game isn't big enough for me to not be able to move to newer versions.
Answer by IgnitedGames · Aug 15, 2019 at 01:06 PM
guys please help I need help
public class Example : $$anonymous$$onoBehaviour
{
// Frame update example: Draws a 10 meter long green line from the position for 1 frame.
void Update()
{
Vector3 forward = transform.TransformDirection(Vector3.forward) * 10;
Debug.DrawRay(player.transform.position + offset, forward, Color.black);
}
}
Is that what you are trying to do?
What I provided is saying this "Draw a black ray from the player's transform center position + the Vector 3 offset you have defined and send that ray forward (0,0,1) for 10 units (meters, whatever)"