Hello, I have some problems with Rigidbodys in my project. I’ll explain what I’m trying to do: The player can click on a certain area on the ground to spawn a rock. The rock moves up from under the ground and then towards the player. The player can then click on the rock to shoot it away.
The first problem: the rock doesn not collide with the player when it’s moving. It moves right through the player, and only collides when it’s standing still. Here’s the code I made:
void OnCollisionEnter (Collision col) {
if (col.gameObject.tag == "Player") {
Debug.Log("col");
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
rigidbody.Sleep();
}
The second problem: when I click the rock, it does not launch itself because the rigidbody is set to Kinematic. When I set it to non-kinematic, the rock glitches out when it moves from under the ground, and launches itself in the air. Here’s the code for the launching:
void OnMouseDown () {
if(distancebetween >10) {
rigidbody.velocity = transform.TransformDirection(new Vector3(0,0,speed));
Debug.Log("clicked FORCE");
}
}
I’ve tried rigidbody.AddForce too, didn’t work. So in short, I need the kinematic because it glitches out if I don’t use it, but I can’t add force to it because it’s kinematic T_T…