I am making a couple of levels that have a wind particle effect that, when the player jumps, the wind’s direction will push the player in that direction. Different rooms will have different directions so it need to be able to tell which way the wind is blowing and push the player in that direction. I got a player with rigidbody that can jump, but that is about all I know how to do.
You can use a trigger collider, to which you add something like :
[SerializeField] Vector3 _dir;
[SerializeField] float _strength;
OnTriggerStay (Collider other)
{
if (!other.attachedRigidbody)
return;
other.attachedRigidbody.AddForce (_dir * _strength, ForceMode.Force);
}
It’s actually pretty simple, you would just constantly add force in which ever direction the “wind” is “blowing”.
private Rigidbody rb;
private Vector3 ThisLevelsWindDir;
private float ForceOfTheWind;
void Start(){
rb = player.GetComponent<Rigidbody>();
}
void Update(){
rb.AddForce (ThisLevelsWindDir*ForceOfTheWind);
if(Input.GetKey (KeyCode.D)){
rb.AddForce (Vector3.right*speed);
}
}