- Home /
Gravity Lift/Jump Pad for FPS game
I have read the Lerpz documentation on creating the jump pad however i want to do this in my FPS game. Here is my script
//----jumppad.js----
var jumpAngle:Vector3; var jumpMagnitude:float=1.0;
function OnControllerColliderHit (entity)
{
//Make sure the triggering entity has a rigidbody before we try to access it!
if(entity.gameObject.tag == "player")
{
print("hit the grav pad");
//Apply the force
entity.rigidbody.AddForce(jumpAngle*jumpMagnitude);
}
}
This script needs a rigid body, which the fps controller doesnt have. The lerpz script references the third person controller but im not sure how to adapt that to the FPS.
If anyone can help i would be massively grateful
Kind Regards
Nick
Don't know if this will interfere with anything but why not try just adding a rigidbody component via Component>Physics>Rigidbody ? You might want to uncheck the useGravity option to avoid 'double' gravity.
hi merry_christmas, can you help take a look on my question(Help in Calculate Point to Point distance)
Answer by jewetnit · May 17, 2013 at 03:34 PM
This is what I used for a jumppad in my game, it's pretty easy Create a cube gameObject and add this script to it. Make sure the box collider Is Trigger is checked. If you want to play a sound when a player uses the jumppad be sure to add an audiosource to the jumppad too. JS:
#pragma strict
var strength : int = 10; // Strenght, how high will the jumppad make the player jump
var jumppadsound : AudioClip; // Sound played when a player uses the jump pad
// make sure to check the Is Trigger checkbox in the Box/mesh/whatever collider
function OnTriggerEnter(col : Collider){
// Make sure the "Player" tag is set on the player
if(col.CompareTag("Player")){
col.gameObject.GetComponent(CharacterMotor).SetVelocity(Vector3.up * strength);
audio.PlayOneShot(jumppadsound);
}
}
@script RequireComponent(AudioSource);
Without sound:
#pragma strict
var strength : int = 10; // Strenght, how high will the jumppad make the player jump
// make sure to check the Is Trigger checkbox in the Box/mesh/whatever collider
function OnTriggerEnter(col : Collider){
// Make sure the "Player" tag is set on the player
if(col.CompareTag("Player")){
col.gameObject.GetComponent(CharacterMotor).SetVelocity(Vector3.up * strength);
}
}