So basicly my game is a 2d birds eye view space game where every object can only move on the x and z axis. The player can fire projectiles at asteroids and i was trying to make an AddForceAtPosition effect when the asteroid is hit to simulate a little more physics realism. I looked at the reference and had a few tries but my code didnt work. I didnt know how to apply the function into my collider code on line 3 because im a noob at functions.
void OnTriggerEnter ( Collider collider){
if(collider.gameObject.CompareTag ("Projectile"))
ApplyForce();
health -= 1;
if(health == 0){
health = 6;
transform.position = new Vector3(Random.Range (-25.0f,25.0f),0,Random.Range (-25.0f,25.0f));
}
}
void ApplyForce(Rigidbody body){
Vector3 direction = body.transform.position - transform.position;
body.AddForceAtPosition(direction.normalized, transform.position);
}
}
What's wrong wrong with it? Errors? Doesn't move at all (and the old version did)? Flies off the wrong way? I'd cut the AddForce function. Esp. since you write that you don't know functions very well. Just copy those two lines back to OnTriggerEnter. It will have the same problems (whatewver they are,) but will be simpler.
– Owen-Reynolds