- Home /
Making isKinematic False When Hit By Colliding Gameobject
Alright, so essentially what I'm looking for is when a bullet collides with another gameobject, it causes it to fall or be moveable again. For instance, a bullet hits a brick wall, turning off the kinematics of the bricks and pushing them inward to expose a hole for the player to walk through.
Here's my current code:
var projectile : Rigidbody;
var speed = 20;
var rate : float = 0.5;
private var rate_time : float;
function Update()
{
if( Input.GetButtonDown("Fire1") && Time.time > rate_time)
{
rate_time = Time.time + rate;
var instantiatedProjectile : Rigidbody = Instantiate(projectile, transform.position, transform.rotation );
instantiatedProjectile.rigidbody.AddForce(instantiatedProjectile.transform.forward * speed);
Physics.IgnoreCollision( instantiatedProjectile. collider, transform.root.collider );
}
}
Any help with integrating the code into that or a better suggestion would be much appreciated!
Answer by Owen-Reynolds · May 11, 2013 at 06:49 AM
That idea works. For example a barrel on a slope which should stick tight until a bullet knocks it loose. Tricky part is assigning a velocity to a "frozen" (isKin) rigidbody is an error, so you may need lots of if(rigidbody.isKinematic==false) checks.
Just use standard moving bullet code, and add the unfreeze line:
void OnCollisionEnter(Collision cc) {
if( we hit something to knock around ) {
cc.rigidbody.isKinematic=false; // <-- just this change to regular bullet hits
...
So if I wanted the bullet to be applying the "is$$anonymous$$inematic = false" and also the force to an object, what would be the coding for that in JavaScript?
I've got this as a start I think:
function OnCollisionEnter(theCollision : Collision){
rigidbody.is$$anonymous$$inematic = false;
rigidbody.WakeUp();
}
WakeUp is a special-purpose command. If you push something, Unity will auto-handle waking up stuff for you.
Look up "Unity OnCollision" examples in any search engine. It will show you how theCollision is the thing you hit, so want to push. Then look up "Unity push object." There are lots of people pushing things using Unity. Player push, bullet push -- same thing.
Your answer
Follow this Question
Related Questions
Problems with save 1 Answer
How to use if statement properly 1 Answer
Make isKinematic false when touching a Collider? 1 Answer
I want some gameobjects are all unactive! 1 Answer
Randomizate bullets help 2 Answers