Hi, I’m new in the unity’s community, I m doing my best to learn as much as I can and I m needing some help !
Here is the story :
I have 2 GameObjects :
- A cube with [Mesh filter, Box Collider, Mesh renderer]
- A sphere with [Mesh filter, Sphere Collider, Mesh renderer] to witch I added my own 2 scripts :
- A control script for mouvement :
var speed : float = 1.0;
var busy : boolean;
function Update () {
if (Input.GetKey(KeyCode.UpArrow))
{
transform.Translate(Vector3.forward * Time.deltaTime * speed);
}
if (Input.GetKey(KeyCode.DownArrow))
{
transform.Translate(Vector3(0,0,-1)*Time.deltaTime * speed);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
transform.Translate(Vector3(-1,0,0)*Time.deltaTime * speed);
}
if (Input.GetKey(KeyCode.RightArrow))
{
transform.Translate(Vector3(1,0,0)*Time.deltaTime * speed);
}
if (Input.GetKey(KeyCode.A))
{
leftPunch();
}
if (Input.GetKey(KeyCode.E))
{
RightPunch();
}
}
function leftPunch()
{
if (!busy)
{
busy=true;
var lh=GameObject.Find("LeftH"); // Here is a smaller children sphere
var pos=lh.transform.position;
lh.transform.Translate(Vector3(0,0,0.065)* speed);
yield WaitForSeconds(0.2);
lh.transform.Translate(Vector3(0,0,-0.065)* speed);
yield WaitForSeconds(0.3);
busy=false;
}
}
function RightPunch()
{
if (!busy)
{
busy=true;
var rh=GameObject.Find("RightH"); // Here is a smaller children sphere
var pos=rh.transform.position;
rh.transform.Translate(Vector3(0,0,0.06)* speed);
yield WaitForSeconds(0.2);
rh.transform.Translate(Vector3(0,0,-0.06)* speed);
yield WaitForSeconds(0.3);
busy=false;
}
}
// I tried this function when I added a character controller component for the sphere
function OnControllerColliderHit (hit : ControllerColliderHit )
{
// Debug.DrawRay(hit.point, hit.normal);
if (hit.moveDirection.y > 0.01)
return;
}
the second scipt I used for the sphere is to see if there is any collision detection when I move the sphere into the cube :
var test : float=1.0;
function Update () {
}
function OnCollisionEnter(contact : Collision)
{
Debug.Log("Collision OK !!");
test=444.0;
}
The problem now is that the collision apparently doesn t happen, nothing is fired on the console, and the sphere can go threw the cube without beeing blocked !
I hope I m not missing a simple stupid stuff and that I m not wasting your time. Thank you for help