Hi, im trying to make a fighting game, and i have two questuion.
So for the punch I’m using raycasting to determine if its hit something and here is the code:
void Shoot ()
{
shootRay.origin = rightHand.transform.position;
shootRay.direction = transform.forward;
if(Physics.Raycast (shootRay, out shootHit, range, shootableMask))
{
Debug.DrawLine(rightHand.transform.position, shootHit.transform.position, Color.red,2.0f);
Rigidbody enemyrigid = shootHit.collider.GetComponent <Rigidbody> ();
// If the EnemyHealth component exist...
if(enemyrigid != null)
{
//enemyrigid.AddForce(shootRay.origin + shootRay.direction * punchPower ,ForceMode.VelocityChange); // Not sure if i should use AddForce Or Velocity
enemyrigid.velocity = (shootHit.point - rightHand.transform.position).normalized * punchPower;
}
}
else
{
Debug.Log(“Didn’t Hit Anything”);
}
}
So my question is:
-
My main question is when i hit Fire Button it shoots ray from like right hand to Shootable thing so im gonna add force in the direction that Raycast draw, is there anyway so i can do it ? you can see the image example
Imgur: The magic of the Internet -
Should i use AddForce or Velocity to move the enemie backward? is there any diffrence? because i tried both of them and both works the same!