- Home /
Add force to player in given direction
I have a fan that adds a varying amount of force to a rigidbody depending on it's distance from the fan and in the direction of the fan:
hit.gameObject.rigidbody.AddForce(transform.up * (Power / Vector3.Distance(hit.transform.position, center.transform.position)));
this is encompassed within an OnTriggerStay function. This makes the rigidbodies get pushed smoothly in the direction of the fan. I'm having a bit of trouble getting this same behavior to work on the player. The player is the default first person character controller. Any help would be much appreciated.
Answer by hav_ngs_ru · Jan 23, 2015 at 01:57 PM
does your player have rigidbody, or controller calculates position by itself? if it has - what are it's settings? if no - then it should be so, because AddForce works only with ohysics objects (withown rigidbody gameobject is not ohysics object, just a ghost). in this case you have to modify default controller and add physics to it (rigidbudy support, or your own forces calculations).