- Home /
Question by
SuperCrusher22 · Aug 21, 2021 at 01:54 AM ·
collisiontriggersbounce
My bounce script is not working, but everything looks right..
So I have still been trying to figure out how to get the ball in my game to bounce whenever it touches an object with the tag "jumpPad". I have tried numerous ways and still have had little to no luck at all. I am trying to use a rigidbody. My script looks right, but nothing happens. I have both gravity and kinematic on. The reason I have kinematic on is because whenever I load the scene, the ball falls through the platforms, even though the colliders are correct. Here is the bounce script I am using:
using UnityEngine;
using System.Collections;
public class bouncer : MonoBehaviour
{
bool jumpEnabled;
public Rigidbody rb;
public float gravityScale = 5;
void Start()
{
jumpEnabled = false;
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (jumpEnabled == true)
{
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "jumpPad") // this string is your newly created tag
{
rb.AddForce(Physics.gravity * (gravityScale - 1));
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Resizing colliders and OnTriggerEnter 0 Answers
Bounce when hitting wall 2 Answers
Activate trigger if items colected 1 Answer
OnCollisionEnter When isTrigger = false 3 Answers
Unrealistic bounce 2 Answers