So I’ve been trying to add a JumpPad to my FPS game. But for some reason it’s not working. I tried some other solutions like Bolt and Playmaker, but they didn’t work either. Please Help.
Here’s My C# Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JumpPad : MonoBehaviour
{
//I am not sure this Range works for the change method of appling the jump force.
[Range(0, 500)]
public float bounceVelocity = 10f; //bounce Velocity in m/s
void OnCollisionEnter(Collision collision)
{
//If you don’t see this message in the console, the collision was not detected.
Debug.Log(“JumpPad collision detected”);
var playerRigidbody = collision.rigidbody;
if (playerRigidbody != null)
{
//Get the players current velocity
var velocity = playerRigidbody.velocity;
//Add the jump velocity in the up direction
velocity.y = bounceVelocity;
//Apply the new velocity to the player
playerRigidbody.velocity = velocity;
}
else
{
//If you see this message the player has no rigidbody component
Debug.Log(“No player rigidbody found!”);
}
}
}
Thankyou