why won’t this work? instead of pressing a button, on collison I want this enemy character controller to jump up…and be affected by gravity e.t.c . It should work, should’nt it? it sucessfully prints “afaf” once it collides… Also I am fairly new to coding.
var jumpspeed = 35;
var up;
var controller;
var isJumping: boolean = false;
function Update()
{
var controller : CharacterController = GetComponent(CharacterController);
up = (Vector3.up);
}
function OnControllerColliderHit(hit:ControllerColliderHit)
{
print("atleastwerehere");
if (hit.gameObject.tag == "Jumppad")
{
print("afaf");
controller.Move(up*jumpspeed);
}
}
You are heading in the right direction, but there are some things you could improve on.
Use a variable called moveDirection
Use that to jump
Something like this:
var jumpSpeed = 35;
private var up = (Vector3.up);
var controller;
var isJumping: boolean = false;
private var moveDirection : Vector3 = Vector3.zero;
function Update()
{
var controller : CharacterController = GetComponent(CharacterController);
}
function OnControllerColliderHit(hit:ControllerColliderHit)
{
print("atleastwerehere");
if (hit.gameObject.tag == "Jumppad")
{
print("afaf");
moveDirection.y = jumpSpeed;
}
}
It should look something like that. It is much better and works really good.