Hi!
I have a problem with this script:
void OnCollisionEnter()
{
}
When i assign that to a first person controller and hit play and run into a cube nothing happens. My cube has a box collider and rigidbody.
Hi!
I have a problem with this script:
void OnCollisionEnter()
{
}
When i assign that to a first person controller and hit play and run into a cube nothing happens. My cube has a box collider and rigidbody.
Firstly, OnCollisionEnter takes a Collision as a parameter. Secondly, there’s nothing in your block of code to execute anyway. ![]()
So i changed my script to this:
using UnityEngine;
using System.Collections;
public class Move_the_box : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter(Collision Cube)
{
if (Cube.gameObject.tag == "Cube")
{
Debug.Log("Hit!");
}
}
}
But that doesnt work either. I tried Cube.gameObject.name == “Cube” but nothing.
Make sure its tagged correctly and you have colliders on your objects. To debug in code just try this:
void OnCollisionEnter(Collision collision)
{
Debug.Log(collision.gameObject.tag);
}
So, i tried this script:
using UnityEngine;
using System.Collections;
public class Move_the_box : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter(Collision Cube)
{
Debug.Log(Cube.gameObject.tag);
}
}
I duplicated my cube and it worked. I also placed that second cube above the first and hit run and when it fell down message in the console “Cube” popped up. So there must be some problem with First person controller
I have the exact same problem. I wanted to make falling platforms by adding gravity when a player jumps on the box but it just won’t happen. I can get another object like a box to fall on the platform and it will act as it should but not with the player controller. I haven’t come up with a work around for this yet but I was going to try adding a seperate box collider as a child and make that the Trigger.
So, nothing??
If you are using the character controller, perhaps this would do you better LINK
I checked out the link and I am getting the controller to interact with the platform. The problem I’m having now is frame rate. Every time the player is touching a platfrom, my frame rate drops to 2 FPS and I can’t figure out why. It’s not in an update function or anything like that. At first I thought it was because I was adding a rigidbody so I changed it to add gravity and that didn’t fix the problem. When I step off the platform, it goes back to 30 FPS. Any ideas what’s going on here? The only thing I can think of is when I’m touching the box, it acts like an update function cause it’s constantly looking to add gravity?
var useGravity : boolean;
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.rigidbody)
{
WaitFor(hit);
}
}
function WaitFor(hit : ControllerColliderHit)
{
print("We are starting to wait");
yield WaitForSeconds(5.0);
hit.rigidbody.useGravity = true;
yield WaitForSeconds(3.0);
Destroy(hit.gameObject);
print("It's been 8 seconds");
}
Use StartCoroutine and see if it stops it from not doing anything.
That is to say, start WaitFor with start coroutine.