So I’m working on a game where the characters are on top of a rigidbody and they push each other away using a fire key. I have a raycast so that I can determine which direction the enemy should be pushed away. So far the raycast detects but when I hit the fire button it returns “MissingMethodException: UnityEngine.Rigidbody.AddForceAtPoint”. Also if it helps the object being hit by the raycast isn’t the rigidbody itself but the game object on top of it.
var ball:Rigidbody;
var bulletForce: int = 100;
function Update () {
var hit:RaycastHit;
var fwd = transform.forward;
Debug.DrawRay(transform.position,fwd ,Color.red);
if (Physics.Raycast (transform.position, fwd, hit)) {
print ("There is something in front of the object!");
if(hit.collider.tag == "Enemy2"){
print(hit.point); //For testing the hit point
if(Input.GetButton("Fire1")){
print("Shit works!");
ball.AddForceAtPoint(bulletForce * fwd,hit.point);
}
}
}
else{
print ("Nothing there!");
}
}