How can I change an objects Kinematic state on impact with player?
So here's the deal, I created an object (a sheep) made out of cubes, that move in a circle (while kinematic). I want it to have an effect where when the player runs into the object, it will no longer be kinematic, essentially causing to fall into a little pile of cubes, and stop moving in a circle. Thanks for the help!
Answer by GAMZER0 · Aug 31, 2015 at 04:20 AM
What you want to do is make an OnCollisionEnter function in the sheep class, and when the player collides with it, set the sheep kinematic to false: isKinematic = false; An example is this: (Note this code hasn't been tested.
public Rigidbody SheepRB; //The sheep rigidbody
void Start()
{
SheepRB = GetComponent<Rigidbody>();
}
void OnCollisionEnter (Collision Col)
{
if(Col.gameObject.tag == "Player")
{
SheepRB.isKinematic = false; //Turns off the Kinematic
}
}
This is perfect thanks! $$anonymous$$y problem was I was using an OnTriggerEnter in the player class, and trying to transfer data to the sheep class somehow. I didn't think to just detect the collision from the sheep class. Good work :)
So I attempted this just now, and for some reason it is not working, and I cant seem to figure it out. Here is what I have: using UnityEngine; using System.Collections; public class Crumble : $$anonymous$$onoBehaviour { %|-609983407_1|% %|221694547_2|% %|373702738_3|% %|-448543543_4|% %|-1327985746_6|% %|-1110813548_7|% %|1691315859_8|% %|1471336863_9|% %|-747104344_10|% %|1802515232_11|% %|1888266136_13|% %|-1619529957_14|% }
I have this script applied to each cube, as well as the parent, and even the prefab that I used. Yet, when the ball passes through the sheep, nothing happens. Is there something I'm missing? Thanks.
What exactly does those codes do that's inside your crumble class? Also make sure player isn't kinematic, and all the objects rigidbodies "Collision detections" is set to continuous
Ah I didnt have my objects set to continuous collision. Thanks again!
No problem, if it still doesn't work just let me know, and I'll try to come up with different solutions to what could be the problem.
Your answer
Follow this Question
Related Questions
Help with a door slam trap 0 Answers
Any ideas in relate to a cube rolling? thank you! 0 Answers
Any way to fix an tag change problem? 1 Answer
How to change isKinematic only in one scene C# 1 Answer
Unity3D: Objects destroy automatically 0 Answers