"Launch" a player

I usually don’t ask for help but I’m trying something new and trying to “launch” a player into the air using a pad that sits on the ground similar to halo and for some reason I’m having trouble with such a simple task. I started out trying an OnCollision RayShoot and figured it would be easier to send a constant ray so the player wouldn’t need to make contact with the pad but instead it just launches my player into the abyss instead of just 20 feet. Here’s my script and any help would be appreciated.

var Range : float = 5;

var Force : float = 5;

function Update()
{

RayShoot();

}

function RayShoot(){

var Hit : RaycastHit;

var DirectionRay = transform.TransformDirection(Vector3.up);

Debug.DrawRay(transform.position, DirectionRay * Range, Color.blue);

if(Physics.Raycast(transform.position, DirectionRay, Hit, Range));

}

Why use raycast? I see no reason why you shouldn't put a box collider around the launch pad as a trigger and use OnTriggerEnter() to give it a force up (and slightly forward probably). Assuming you use a rigidbody, of course

2 Answers

2

ok I think I just found the problem why I’m struggling with testing my script. Somewhere in the scripting of the first person character controller provided with unity and even 2 of my own character controllers, all 3 do not support rigidbodies. Ive never actually put a rigidbody onto a character controller. If you attach it and you jump and immediately press forward you launch straight up about 500 ft and I’m guessing the longer you hold jump the higher you go. Well thank for your response and I’m going to try and find a work around

Right, I forgot about that. I never use the premade controller, you see. In that case, how about checking out the jump bit in the controller script and mimicking it, but with a lot more force?

Yeah, the character controller is pretty damn frustrating to use.

ok thanks. working perfectly now. just wrote all new scripts this morning so I won’t run into that problem on future developments

Good to hear you solved it. You'll want to accept one of the answers so the question won't appear on the 'unanswered' list anymore. :)