hello all,
working on character hit to an object.
I searched the thing i need in forums but still couldn’t get the right idea about that.
Now in here the character is having punch animation. And in the punch i have added the collider. Now a rigidbody cube is there on the floor. So when reaching towards cube and punching the cube is moved and reacting properly regarding the place its got hit and the direction its thrown too.
But than again needed the force (like thrown away with speed) to work on it in the same way its got hit. And i have attached script for detection of the punch on the cube itself.
like finding true or false for hit(for work under fixed update other wise the cube will directly start moving by itself).
So,if it gets hit than the cube should move in that direction like thrown away as in the direction its hit but with full speed.
This is the script on the cube for detection and applying force
forceCheck.js
var hitted : boolean;
function FixedUpdate()
{
if(hitted == true)
{
var dir = transform.TransformDirection(Vector3.forward);
constantForce.relativeForce = dir * 500;
}
}
function OnCollisionEnter(colliInfo : Collision)
{
if(colliInfo.gameObject.tag == "punchHit")
{
hitted = true;
}
}
Also i have used freeze rotation on cube.
And so the above code the cube is thrown away fast but in only single direction, no matter where or on which side the cube gets hit.
If i don’t use freeze rotation than the cube is floating everywhere or if the forward pull is towards the downward direction than it acts like a magnet being stuck on the floor.
i think its may be somewhere near the problem. Or there is some other clear method.