(SOLVED... basically)Jump Pad help

(sorry for wall of text)

Hey there guys, love the forum and all the help everyone provides. Im just in the middle of making a “maze” style game where the player progresses through a maze and you can choose to use various pick ups.

One of these ,(well not really a pickup) is the “1Jump” pickup. Basically it’s a trigged box collider that will use the Jumppad script (hopefully) from the Platform Tutorial.

Here is my Dilemma: Im using the FPSWalker script to control the character, it was easier and more efficient because i could lock the camera in a certain position whilst moving the character around.

I’ve referred to Tysoe’s post in

http://forum.unity3d.com/viewtopic.php?p=279055

basically i’ve moved the functions of: CalculateJumpVerticalSpeed and both Superjumps into the FPSWalker script.

What i’m trying to do is call these functions from the Jumppad script assigned to the current gameobject im going to use.

It’s started with this

var controller : ThirdPersonController= col.GetComponent(ThirdPersonController);

and Here is where i am stumped. because i’m using the FPSWalker script instead of the ThirdPersonController script should i substitute CharacterController in ? like so ?

var controller : CharacterController = col.GetComponent(CharacterController);

im stuck!

bump, i’m still stumped with this, no possible help ?

I read your post a couple of times, but wasn’t really able to understand the problem.

Someone else might come along and offer some suggestions, but it might help if you could break the problem down for us and include all of the relevant info here in the thread (just so we don’t have to read through multiple threads in order to understand what’s going on).

Sorry if i wasnt clear, i tried explaining but i guess i failed haha. Basically what’s happening is i get a problem of “superJump” is not a member of UnityEngine.CharacterController.

So im thinking of an alternative at the moment,
here is my FPSWalker Script

var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;

private var moveDirection = Vector3.zero;
private var grounded : boolean = false;

function FixedUpdate() {
	if (grounded) {
		// We are grounded, so recalculate movedirection directly from axes
		moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
		moveDirection = transform.TransformDirection(moveDirection);
		moveDirection *= speed;
		
		if (Input.GetButton ("Jump")) {
			moveDirection.y = jumpSpeed;
		}
	}

	// Apply gravity
	moveDirection.y -= gravity * Time.deltaTime;
	
	// Move the controller
	var controller : CharacterController = GetComponent(CharacterController);
	var flags = controller.Move(moveDirection * Time.deltaTime);
	grounded = (flags  CollisionFlags.CollidedBelow) != 0;
}
function CalculateJumpVerticalSpeed (targetJumpHeight : float)
{
	// From the jump height and gravity we deduce the upwards speed 
	// for the character to reach at the apex.
	return Mathf.Sqrt(2 * targetJumpHeight * gravity);
}
function SuperJump (height : float) 
{ 
   verticalSpeed = CalculateJumpVerticalSpeed (height); 
   collisionFlags = CollisionFlags.None; 
   SendMessage("DidJump", SendMessageOptions.DontRequireReceiver); 
} 

function SuperJump (height : float, jumpVelocity : Vector3) 
{ 
   verticalSpeed = CalculateJumpVerticalSpeed (height); 
   inAirVelocity = jumpVelocity; 
    
   collisionFlags = CollisionFlags.None; 
   SendMessage("DidJump", SendMessageOptions.DontRequireReceiver); 
}

@script RequireComponent(BoxCollider)
@script AddComponentMenu("Third Person Player/Third Person Controller")

and here is my Jumppad script

var jumpHeight = 5.0;

function OnTriggerEnter (col : Collider) 
{
	var controller : CharacterController = col.GetComponent(CharacterController);
	if (controller != null)
	{
		if (audio) 
		{
			audio.Play();
		}

		CharacterController.SuperJump(jumpHeight);
	}
	
}


// Auto setup the script and associated trigger.
function Reset ()
{
	if (collider == null)	
		gameObject.AddComponent(BoxCollider);
	collider.isTrigger = true;
}

@script RequireComponent(BoxCollider)
@script AddComponentMenu("Third Person Props/Jump pad")

i guess the problem i’m having is calling upon the superjump function from FPSWalker?

thanks for the help in advance!

I was looking around and thinking. What if i just put a simple rigidbody command on the trigger?

like this:

var jumpHeight = 5.0;



function OnTriggerEnter (col : Collider) 
{
	
	rigidbody.velocity.y = 10;
}
function Reset ()
{
	if (collider == null)	
		gameObject.AddComponent(BoxCollider);
	collider.isTrigger = true;
}
 

@script RequireComponent(BoxCollider)

but now i’m wondering, should i have both a Character Controller and a Rigidbody? or is that a no go.

also, the problem i’m encountering is i don’t know how to make the trigger target the rigidbody of my character, it just tells me there is no rigidbody for my Jumppad. How do i call upon a rigidbody from a different GameObject?

thank you

Is it ‘superJump’, or ‘SuperJump’?

It may seem like a small detail, but with case-sensitive languages, it makes a difference. (It’s not unheard of to have a variable and a function with the same name aside from case, so I think the first step here is to clarify what you’re referring to exactly.)

it’s SuperJump, my bad.

but i’ve moved on from that idea. unless you think it’s a better idea than what i have now.

Im trying to call upon the First Person Controller’s (the prefab that i’m using)CharacterController (or rigid body, im really confused about which to use) to have it’s Y velocity or general upwards direction increased.

is that possible to do from a trigger?

You’ll most likely need to incorporate the ‘jumping’ functionality into whatever script is controlling the character controller’s linear motion. In the ‘first person controller’ prefab that comes with Unity, for example, this is the FPSWalker script (I think). If you’re using that script or a variant thereof, then that’s where you’ll want to add the logic for jumping and/or being propelled by a jump pad.

Thank you for the prompt reply Jesse,

When i was still trying to call upon functions from the FPSWalker script (the “SuperJump” functions from the Jumppad script found in the 3d platform tutorial) i had moved everything relevant in and i could not call upon it for some reason.

Now i have come up with this, which basically accomplishes what i wanted to achieve but with one hiccup: I have to already be in mid air for the trigger to affect my jump (that is, i have to jump before hitting the trigger, then i get an added “Bounce” from the jumpHeight in the script below), if i just run into the trigger nothing happens, and if i run into the trigger THEN jump nothing happens.

How can i make it just launch me when i hit the pad?

var jumpHeight =20;

function OnTriggerEnter (col : Collider) 
{
	var controller : FPSWalker = col.GetComponent(FPSWalker);
	
	controller.moveDirection.y = jumpHeight;

}

@script RequireComponent(BoxCollider)

I think the logic will have to be a little more involved than simply assigning a value to moveDirection.y. I don’t have the FPSWalker script in front of me right now, but take a look at the code and see how the logic is arranged. There’s most likely some logic related to being ‘grounded’ in there, and it’s possible that your modification of the moveDirection ‘y’ value is being overwritten or reset at some point.

If you need a hint as to how to proceed, take a look at the script to see how it handles jumping (if it handles jumping - I can’t remember for sure). Basically, what you want to do when a jump pad is encountered is to instigate a ‘jump’, but with a higher than normal ‘y’ velocity. By moving the ‘jump’ code out of Update() or FixedUpdate() and into a separate function, making the y velocity an argument, and then calling that function with an appropriate value when a jump pad is encountered, you should be able to get the effect you’re looking for.

Really, it’s all about breaking the problem into steps, thinking through what needs to happen logically, and then writing code that implements that logic. Easier said than done sometimes, I realize, but that’s the way to go about solving problems like this. (If you get hung up on the logic, it can sometimes help to create a flowchart or pseudocode outlining the basics of what needs to happen.)