- Home /
How Can I Make A Platform Lauch My PLayer Into The Air?
I'm trying tot make a game like redball and if you have ever played redball you would see that there are platforms that lauch the ball into the air. How can I copy this.
Answer by SarperS · Oct 03, 2012 at 06:34 AM
I don't know Redball but you can add a trigger volume to that platform, once the player triggers the volume, you can set the Y velocity of it's rigidbody to something high enough to shoot the player into the air. Gravity will take care of the rest.
can i use this code to change the velocity of an object upon collision? whats the code for prefor$$anonymous$$g such an action?
function OnTriggerEnter (other : Collider) {
//need code to change velocity here
}
Thank You I haven't tried it yet but it sounds like it will definitely work.
Haha, it actually didn't work. I wrote my script like this:
var LaunchHeight = 8; function OnTriggerEnter (other : Collider) { other.rigidbody.velocity.y = LaunchHeight;}
Then this errors occurs:
NullReferenceException: Object reference not set to an instance of an object
I might add that my player has character controller not rigidbody.
Well you never mentioned it was a character controller, please post your movement script and let's see if you have jump controls, if you utilize the Y component of your movement vectors, you might be able to alter that jumpspeed high enough to achieve that jumppad effect.
Answer by Dark44Mod · Mar 09, 2017 at 05:42 PM
Try adding a tag to the platform called "launcher" or something like that and then in your player controller script: add an if statement that would check the tag on the platform and inside the if statement add a rigidbody AddForce to move the player up. Something like this (I am NOT an expert so, loosely follow this):
public float VerticalForce1 = 10f; //Change this for your launching power
Vector2 VerticalLauncher = (0, VerticalForce1);
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag ("launcher"))
{
rb2d.AddForce (VerticalLauncher);
}
}
Did you realize that this question is 5 years old? And your answer is basically the same with $$anonymous$$e, the OP is not using a Rigidbody so this wouldn't work.