Hi everyone, I have been a using a SphereCast instead of a Raycast to try and make it more inaccurate. However my SphereCast doesn’t seem that inaccurate and still misses the object I want to hit. Any idea what is wrong with my script?
public float Distance = 100;
public RaycastHit hit;
if(Physics.SphereCast(gameObject.transform.position, 0.5f, transform.forward, out hit, Distance))
The only problem might be the physics not being updated when you call the sphere cast if the object is moving fast. You should try doing a Debug.DrawRay to ensure that you are pointing where you think you are.
– whydoidoitJust as long as you understand the difference between Vector3.forward and transform.forward. Vector3.forward is in world space, meaning that it always points along the world's z axis, while transform.forward is in local space, meaning that it points along the transform's z axis. Is your transform rotated 90 degrees along the x axis? This would cause transform.forward to point down.
– iwaldrop