im trying to make the player jump when the raycast hits a block
this is what is have so far
please edit this
var Blocks : GameObject;
var Player : GameObject;
var Range : float = 10;
function Update () {
var fwd = transform.TransformDirection (Vector3.forward);
var hit : RaycastHit;
Debug.DrawRay(transform.position, fwd * 50, Color.green);
if (Physics.Raycast (transform.position, fwd, hit, Range));
hit.Blocks.( Player.transform.Vector3.up);
}
Hello allenziff,
This code is pretty weird…no offense. You could do multiple things, send a message or apply your script to the player. The second 1 is pretty easy:
var Blocks : GameObject;
var Player : GameObject;
var Range : float = 10;
function Update () {
var fwd = transform.TransformDirection (Vector3.forward);
var hit : RaycastHit;
Debug.DrawRay(transform.position, fwd * 50, Color.green);
if (Physics.Raycast (transform.position, fwd, hit, Range));
transform.Translate(0, 5, 0);//or whatever you use to jump.
}
then the first solution, what you need is: a script with a function to jump applied to the player, and the script you posted here(or what im gonna post).
here it is:
var Blocks : GameObject;
var Player : GameObject;
var Range : float = 10;
function Update () {
var fwd = transform.TransformDirection (Vector3.forward);
var hit : RaycastHit;
Debug.DrawRay(transform.position, fwd * 50, Color.green);
if (Physics.Raycast (transform.position, fwd, hit, Range));
Player.SendMessage("Jump", SendMessageOptions.DontRequireReceiver);
}
If you want to define height, instead of the last line, use this:
Player.SendMessage("Jump", 10, SendMessageOptions.DontRequireReceiver);
And you will need a function like this:
function Jump(height : int){
//jump stuff where you use the height of the var in the function
}
Good luck,
-Hybris
Perhaps you should replace Raycast by Linecast. Its more cheaper as we dont know how many processes you are running at the same time in your game.