I’m making a variation on the tilting maze with a ball, but instead of using keystroke input to tilt the platform I’d like the platform to tilt automatically when the ball enters one of the colliders on all four sides. I’d like the ball to start in the middle of a flat platform and then once hit by a paddle, enter one of the four colliders. Once the ball triggers a collider the platform would tilt, sending the ball back into the opposite side. I’ve figured out how to make the basic tilt table using arrow keys to move it, but I’m not sure how to use colliders to accomplish the same thing. Is it possible to use colliders in this way? Here’s the script I started working with:
public class tilt1 : MonoBehaviour {
public Vector3 currentRot;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
You basically need to put your rotate code in OnCollisionEnter (other : Collision){} and remove the Input methods. It’s probably easiest to put different scripts on each collider individually.
Thank you for responding Seppi! It sounds pretty straight forward when you say it, but I’m not sure how to implement it. Can you show me what you mean in a brief script?
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void OnCollisionEnter(Collision collision)
{
//Rotate Code Here
}
}
Then make a new one of those for every collider with the corresponding behavior.
Thanks, but for some reason it didn’t work. Here is the code I used on a collider that the ball passes through.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
void OnCollisionEnter(Collision collision)
{
transform.Rotate (0, 0, 1);
}
}
I still have the input controls for the arrow keys being used on the table. Would they be creating a conflict with the collider?
It’s probably working. OnCollisionEnter is called on;y when the collision happens. So your code is rotating the object by one degree when the collision occurs. You need to have it lerp to whatever rotation you need.