Custom Vector 3

Hey Folks :slight_smile:

I do some raycasting to check whether it hit an object or not. Now I like to cast two more rays.

I know that I can writ down Vector3.forward as Vector(0, 0, 1).

my raycast-code is:

Physics.Raycast(transform.position, transform.forward, hit, raydistance))

but when I try to replace “forward” with my custom vector (0,-1,1) then I get an error message.

Do you know why? Or sould I rather use diferent methods than raycasting if I wanted to cast more than one ray from an object?

Cheers!

Dawnreaver

Maybe posting the line of code that’s not working along with the error message would help. :wink:

Thats actually a good idea :smile:

// this script lets the player collect stones
static var stonecount = 0;
// length of the cast ray
var raydistance : float = 2;


function Update () 
{

var hit : RaycastHit;

if(Physics.Raycast(transform.position, transform.Vector3(0,0,1), hit, raydistance))
	{
	// tests if the ray is hitting a stone, if no the player plays a sound, if yes the stone gets collected 
		if(Input.GetButtonDown("Grab_Object"))
		{
			if(hit.collider.gameObject.tag != "stone")
				{
				audio.Play();
				}
			if(hit.collider.gameObject.tag =="stone")
				{
					stonecount += 1;
					Destroy(hit.collider.gameObject);
				}
		}
// tests if there is an object in the way when the player puts down the stone
		if(Input.GetButtonDown("Drop_Object"))
			{
			if(hit.collider.gameObject.tag =="stone")
				{
				audio.Play();
				}
			}
	}
}

and the error message:

‘Vector3’ is not a member of ‘UnityEngine.Transfrom’

Replace:
transform.Vector3(0,0,1)
with:
new Vector3(0,0,1)

(Note that this is to solve your error, haven’t looked at what you are trying to actually achieve).

Essentially, transform.forward just converts the <0,0,1> vector from the object’s local space to world space. If you want to do this with an arbitrary vector, you can use transform.TransformDirection.