- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
GreenTitan · Mar 12, 2014 at 04:52 AM ·
raycastvector3axisspherecast
How to Spherecast/Raycast diagonally?
This is the script I am using right now.
Radius is a variable representing the radius of the spherecast. Distance is the variable representing the distance of the spherecast RayPos is a variable representing the origin of the spherecast
var Hit : RaycastHit;
//This one works
if(Physics.SphereCast( RayPos, Radius, transform.forward, Hit , Distance))
{
if( Hit.collider.tag == "Player")
{
Debug.Log( Hit.distance);
}
}
//This does not work.
//This is meant to spherecast 45 degrees to the right.
if(Physics.SphereCast( RayPos, Radius, Vector3(1,0,1), Hit , Distance))
{
if( Hit.collider.tag == "Player")
{
Debug.Log( Hit.distance);
}
}
//This does not work.
//This is meant to spherecast 45 degrees to the left.
if(Physics.SphereCast( RayPos, Radius, Vector3(-1,0,1), Hit , Distance))
{
if( Hit.collider.tag == "Player")
{
Debug.Log( Hit.distance);
}
}
Extra Info about what I want to do. I want to detect the capsule which is standing infront the stairs but the lady with the black clothes only detects the capsule if it is infront him.
photo2.png
(174.0 kB)
Comment
Answer by beck · Mar 12, 2014 at 05:36 AM
When you create a Vector3 from scratch, your direction is in world space, and not relative to the player. If you're working with degrees, you can do this:
Quaternion.Euler(0,45,0) * transform.forward
That statement means "rotate the transform's forward vector by 45 degrees around the Y axis".