- Home /
Question by
MrSteve1 · Mar 23, 2014 at 03:16 PM ·
addforcedirectionwindaddrelativeforce
AddRelativeForce to another object
Hi Guys,
This might be really simple but it's had me stumped for about an hour now. I am trying to create a fan, which blows other games objects in which ever direction it is facing. Simple enough but I can't work out what I m doing wrong. This script;
var force : float;
var contact : GameObject;
var myPos : Vector3;
function FixedUpdate()
{
myPos = gameObject.transform.position;
}
function OnTriggerStay(other:Collider)
{
if(other.gameObject.tag == "Player")
{
contact = other.gameObject;
contact.rigidbody.AddRelativeForce(Vector3.up * force * Time.deltaTime);
}
}
Adds relative force based on the orientation of the object itself, not the direction of the fan. Can some clever folk please advise, many thanks in advance!
Comment
Answer by robertbu · Mar 23, 2014 at 08:16 PM
Assuming the 'up' side of the fan is the one that need to blow, I think you want:
if(other.gameObject.tag == "Player")
{
other.rigidbody.AddForce(transform.up * force * Time.deltaTime);
}
That doesn´t work for me :-( The gameOject will be pushed to the direction of its own but not to the direction of the Fan.