- Home /
Given 2 input floats (horizontal, vertical), cast a ray orthogonal to the normal of the surface in direction of input floats?
Ray walledRay;
RaycastHit walledHit;
Vector3 walledRayHeading;
Vector3 walledRayNormal;
Vector3 walledRayDirection;
walledRayHeading = new Vector3(myTransform.position.x + leftInputVertical, myTransform.position.y, myTransform.position.z - leftInputHorizontal) - myTransform.position;
walledRayNormal = Vector3.Cross(walledRayHeading, myNormal);
walledRayDirection = walledRayHeading * (boxCollider.size.x * boxCollider.transform.localScale.x);
walledRay = new Ray(myTransform.position, walledRayDirection);
Debug.DrawRay(myTransform.position, walledRayNormal);
This is what I have so far... Without the cross product in there it works, but only on the Vector3.up normal... When I add the cross product in there, it does some funky stuff and I do not think it is the right solution to this. Vector3.projectonplane is like the opposite of what I'm going for pretty much, haha. Oh, and I forgot to mention but I would like the raycast to be in the direction of the inputs! Thank you if you read this :)
im not sure what you are asking.
are you simply wanting to shoot a ray that remains parallel to whatever angle of the ground you're standing on?
Raycast need an origin and a direction. for the origin you would simply get the players location.
for the direction you would start by getting the angle of the ground you are standing on however you want to do that.
and then change the y as needed probably the players y + input float. but that would only be one input float.
so you need x and z from the ground and change y to whatever ya want
in 3d space there is only three axis. so if you want to absourb the two axis from the ground and change two thats 4. so i would assume you want one of the axis reletive? I would personally set up a child object that can have its local rotation adjused for reference.