I have a ball and a wall. The ball slides through the wall. OnCollisionEnter is never called. Both have Rigidbody attached, physics material, isTrigger=off, isKinematic=off. I do not use transforms. For the ball, I have:
void FixedUpdate() { float move_h = Input.GetAxis("Horizontal"); float move_v = Input.GetAxis("Vertical"); rgdblue = GetComponent<Rigidbody>(); Vector3 movement = new Vector3(move_h, 0.0f, move_v); rgdblue.velocity = new Vector3(0.5f * bluerotationSpeed * Time.deltaTime, 0); rgdblue.AddForce(movement * bluerotationSpeed, ForceMode.Force); }
bluerotationSpeed is public (set to various values from 50 to 200 with no effect). What am I missing or doing wrong? The same script is used in Start(){}. My OnCollisionEnter uses System.Console.WriteLine(“hit”); to inform me when a hit occurs.
I did use the 101/010 icon to enter my code. It added a pair of back-quotes with “enter code here” inside. Tried doing it again here and got a long string as before.
After adding the horizontal rule, I got the proper pop-up window and was able to enter the code below. But before posting it, I inserted: print(“collision”); and it DID print on the console, although the System.Console.WriteLine did not. So my function IS being entered and my original problem can be closed. I’ll have to see why the JS ‘print’ worked and the C# version failed.
void OnCollisionEnter(Collision who )
{
string objname = who.gameObject.name;
if objname == "platform") { System.Console.WriteLine("hit-p"); return; }
else if (who.gameObject.tag == "iswall") { System.Console.WriteLine("hit-wall"); }
else System.Console.WriteLine("hit"+objname);
rgdblue=GetComponent<Rigidbody>();
}