- Home /
Question by
jmgek · Aug 17, 2015 at 07:26 PM ·
raycasting
Proper way to handle this raycast?
Hey guys, I am creating a object holder and I am a little stuck. I am looking to cast a raycast from the users position onto any surface and be offset by itself to stop objects from going into walls. This is what I have so far.
Vector3 fwd2 = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, fwd2 + new Vector3(0, -(gameObject.transform.localScale.y * 0.1f), 0), out hit, 6f, LayerToIgnore))
{
//GameObject position logic
}
This works perfect for the floor but as you can see the raycast is always being offset by -y How could I go about multiplying this by the characters camera angle to allow the raycast to work on walls, roofs, other objects?
Thanks!
Comment
Okay I am getting a little progress,
if (Physics.Raycast(transform.position, fwd2 + new Vector3(-(gameObject.transform.localScale.y * transform.rotation.z), -(gameObject.transform.localScale.y * transform.rotation.x), -(gameObject.transform.localScale.y * transform.rotation.y)), out hit, 6f, LayerToIgnore))
{
Your answer