- Home /
C# Raycast from Object direction (z-axis) + another Vector3
Hello, I cannot mannage to find a way to shoot 4 rays with diffrent vector3 from a objects direction (the z axis).
it works find for one direction but when i rotate the object the ray stays in the same direction. What i want is that the direction change based on the rotation.
private Vector3 topLeft = new Vector3(-0.5f,0.5f,1.0f);
private Vector3 topRight = new Vector3(0.5f,0.5f,1.0f);
private Vector3 buttomLeft = new Vector3(-0.5f,-0.5f,1.0f);
private Vector3 buttomRight = new Vector3(0.5f,-0.5f,1.0f);
private int rayHits = 0;
if (Physics.Raycast(transform.position, (transform.forward * topLeft), out hit, wallJumpDistance))
{
rayHits++;
}
if (Physics.Raycast(transform.position, (transform.forward * topLeft), out hit, wallJumpDistance))
{
rayHits++;
}
if (Physics.Raycast(transform.position, (transform.forward * topLeft), out hit, wallJumpDistance))
{
rayHits++;
}
if (Physics.Raycast(transform.position, (transform.forward * topLeft), out hit, wallJumpDistance))
{
rayHits++;
}
Thanks for helping :)
Comment
Answer by Megdiche Entreprises · Dec 25, 2015 at 01:06 AM
I think I have the same problem, I've tried to find a built-in function in unity but failed instead you can spit some good old trigonometry or create an object that is parented to the origin of your ray and set it as the endpoint and remove the mesh renderer to make invisible