(please forgive me for my bad coding skills)
So im trying to make a jumppad in unity where, if the player stands on the jump pad, the player automatically gets shot up into the sky.
float height = 50f;
else if (onJumpPad)
{
while (true) {
velocity.y += 1;
height -= 1;
if (height == 0)
{
height = 50f;
break;
}
}
}
above is the half-working code. I have to jump ON the jump pad to make the player get shot up into the sky.
Any help is appreciated.
(I know that the height variable should not belong in the middle of the else if statement, I just wrote it for demonstration purposes).
full code here = https://pastebin.com/3ZVu5bUq
I think you might need kind of jump pad. So First of all don't forget to add a collider on block as much height and width as you need. Then you can check with OnTriggerEnter or OnCollisionEnter. For Example:-
I have a block named jumpPad. I added a box collider on that with full of width and with minimum height. I didn't checked IsTrigger so I have to use OnCollisionEnter. Now what I will write in code inside player script is:-
void OnCollisionEnter(Collision other)
{
if(other.gameObject.CompareTag("jumpPad")
{
GetComponent<Rigidbody>().AddForce(Vector3.Up * force);
}
}
In this code force is already declared somewhere in script. Also make sure to give block a tag if you are using CompareTag or .tag == "jumpPad". Also you need to add rigidbody component to player object.