- Home /
Physics.SphereCast problem? center of SphereCast different from center of its transform
Anyone has expererienced this problem with Physics.SphereCast? I mean, it seems that the center of SphereCast is different from the center of its transform.
if you add a sphere collider to a game object and try this code the behaviour is not the expected behavior (SphereCast doesn't return true when you expect, its like the spherecast is shifted):
using UnityEngine;
public class test : MonoBehaviour {
public bool onGroundDown=false; public bool onGroundLat=false; public bool onGroundFront=false; public SphereCollider sphereCollider; RaycastHit hitdown; RaycastHit hitlat; RaycastHit hitfront;
void FixedUpdate(){ onGroundDown=Physics.SphereCast(transform.position, sphereCollider.radius, -transform.up , out hitdown , sphereCollider.radius); onGroundLat=Physics.SphereCast(transform.position, sphereCollider.radius, -transform.right , out hitlat, sphereCollider.radius); onGroundFront=Physics.SphereCast(transform.position, sphereCollider.radius, -transform.forward , out hitfront , sphereCollider.radius); } }
instead with this code it works like expected:
using UnityEngine;
public class test : MonoBehaviour {
public bool onGroundDown=false; public bool onGroundLat=false; public bool onGroundFront=false; public SphereCollider sphereCollider; RaycastHit hitdown; RaycastHit hitlat; RaycastHit hitfront;
void FixedUpdate(){ Vector3 sphereCenter=new Vector3(transform.position.x+sphereCollider.radius,transform.position.y+sphereCollider.radius,transform.position.z+sphereCollider.radius);
onGroundDown=Physics.SphereCast(sphereCenter, sphereCollider.radius, -transform.up , out hitdown , sphereCollider.radius); onGroundLat=Physics.SphereCast(sphereCenter, sphereCollider.radius, -transform.right , out hitlat, sphereCollider.radius); onGroundFront=Physics.SphereCast(sphereCenter, sphereCollider.radius, -transform.forward , out hitfront , sphereCollider.radius); } }
Is this behavior wanted or is an error of SphereCast?
UPDATE 11/05/10 IS it possible that anybody can help me with this problem? Its a week that this question is still open.
This is a duplicate of (http://answers.unity3d.com/questions/25603/physics-spherecast-problem-center-of-spherecast-different-from-center-of-its-tra) Please do not duplicate questions. If you are not getting any answers, consider ins$$anonymous$$d revising your question.