ok so ive got an inventory system that when i pick up the rock i can move it into a holding slot and it apears in my hands what i want to do is throw it out of my hands and to do this i need to unparent it from my hands and turn is kinematic off here is what i have so far can anyone help me implement this?
var Throw : Transform;
function Update() {
if(Input.GetButtonUp("Fire1")) {
var projectile = Instantiate(Throw,
transform.position,
transform.rotation);
projectile.rigidbody.AddForce(transform.right * 10000);
Physics.IgnoreCollision(projectile.collider, collider);
}
}
//what i need to do
//un parent from arms
//disable is kinemetic
//launch forward with set power and remove from hands so it dosent use clones
The weapons that are picked up are placed into this hierarchy of the hands
main camera
arms05
arm_armature
master
innerarm_r
arm_r
hand_r
melee
It is really hard to go from what you have here to what you say you need. That is the code above has nothing to do with getting an object from inventory and placing it in the hand. It is just some generic code, so at best we can only guess at how you are storing the object. Roughly: object.transform.parent = null; object.rigidbody.isKinematic = false; Physics.IgnoreCollision(object.collider, hand.collider); projectile.rigidbody.AddForce(transform.forward * 1000); Some of this is iffy. The direction to AddForce will depend on how you've set things up.
– robertbuthe inventory and adding it is already in place and does not need to be done all i am doing is adding a script to the rock being placed in it to be able to throw it and thanks for your reply i will try some of this tonight
– PvTGregok ive got it working but sometimes when throwing the rock it throws it straight up into the air any ideas?
– PvTGregvar Throw : Transform; function Update() { if(Input.GetButtonUp("Fire1")) { var projectile = Instantiate(Throw,transform.position, transform.rotation); parent = null; projectile.rigidbody.AddForce(transform.forward * 6000); Physics.IgnoreCollision(projectile.collider, collider); } }
– PvTGreg