- Home /
Pinball bumper only works once
I've made a script for a pinball bumper and it works fine for the first contact but afterwards the pinball will not make contact and fall through. Does this have to do with the material of the bumper or the way OnTriggerEnter works?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BumperScript : MonoBehaviour
{
public int bumperForce = 800;
private GameObject player;
// Use this for initialization
void Start () {
Debug.Log ("found");
player = GameObject.FindGameObjectWithTag ("Ball");
}
public void OnTriggerEnter (Collider collider)
{
if (collider.gameObject == player)
{
Debug.Log ("collision");
player.GetComponent<Rigidbody> ().AddExplosionForce (bumperForce, transform.position, 1);
}
}
// Update is called once per frame
void Update () {
}
}
Answer by WarmedxMints · Mar 22, 2019 at 10:46 PM
The likely cause is that your rigidbody is moving too fast and misses the collider. Basically, it moves through it within a frame.
What I would do is first make sure the balls rigidbody is set to continuous detection. I would also consider making the wall solid with a rigidbody and a non-trigger collider and then applying a physics material to the collider which will cause the ball to bounce.
Your answer
Follow this Question
Related Questions
2D 360 degress platformer example needed 0 Answers
How to make pinball flipper 0 Answers
Increase force of JointSpring? 0 Answers
How to make Pinball functionality? 5 Answers
PINBALL: Ball colliding problems 1 Answer