My OnCollisonEnter doesn't detect collison.
EDIT: I forgot to mention I use the roll-a-ball tutorial movement to move my sphere if that helps
I've spent hours trying to find a solution to this problem. The tags are in place. I try to move OnCollisonEnter to void Update() and it just creates tons of error no matter what I enter or remove. Please don't be cryptic with your answer or to look more into it because I've done that for 6 hours all ready.
using UnityEngine; using System.Collections;
public class Jump : MonoBehaviour { public bool OnGround; private Rigidbody rb;
void Start()
{
OnGround = true;
Debug.Log("OnGround set to true in Start");
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (OnGround)
{
if (Input.GetButton("Jump"))
{
rb.velocity = new Vector3(0.0f, 10f, 0.0f);
OnGround = false;
Debug.Log("OnGround set to false in Update");
}
else
{
}
}
}
void OnCollisonEnter(Collision other)
{
Debug.Log("Collision entered with tag named: " + other.gameObject.tag);
if (other.gameObject.CompareTag("Ground"))
{
OnGround = true;
Debug.Log("OnGround Set To true in OnCollisionEnter, collided with tag: " + other.gameObject.tag);
}
else
{
OnGround = false;
Debug.Log("OnGround Set To false in OnCollisionEnter, collided with tag: " + other.gameObject.tag);
}
}
}
In debug menu it starts off a as grounded == true then when it jumps it switches to false but the collision with the "ground"(a plane with the tag ground) doesn't switch the grounded value back to true
what I meant was which of the Debug.Log messages did you reach?
Does your person just go through the ground then?
And both are 3D objects?
Are either of them flagged as a Trigger? Could you screenshot your physics layer settings?
no, the sphere collides with the ground
yes, and yes they are and the sphere has a rigidbody
what do you mean flagged as trigger? If OnCollisionEnter acts as a trigger the sphere is the trigger also how do I use physics layer settings?
Answer by dragonking300 · Nov 17, 2016 at 10:32 PM
Update: so apparently setting the sphere to the ground tag as well makes it magically work .-.
Could you tell me why that is?
then the question is where did you attach the script.If it now works it's not in the sphere but the other way around
Your answer
Follow this Question
Related Questions
HELP! How to make Update function start after delay? C# 2 Answers
How to make a thrown object land on a certain point e.g a thrown spear landing on its tip 0 Answers
Problems with respawning using a very simple script 1 Answer
Having trouble deleting objects from a list after they reach a certain scale. 0 Answers
Rotate Player 90 degrees about its Y axis relative to the mouse being dragged between two angles 1 Answer