Hello, I’m trying to make an obstacle in my game. It’s like the bumpers you get in Pinball machines. When the player touches it, it’s meant to bounce them off.
Getting that to work was easy enough, but I want it to be slightly biased into pushing them sideways, as opposed to upwards.
Here is my code:
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
Vector3 Direction = other.transform.position - Collider.transform.position;
Direction = Direction.normalized;
Vector3 Bias = Vector3.one - transform.up;
Direction = Vector3.Lerp(Direction, Vector3.Scale(Direction, Bias), VerticalityBias);
other.GetComponent<Rigidbody>().velocity = Direction * BounceForce;
}
}
As you can see, it’s a sphere, and the player gets pushed directly away from the center. But what I am trying to do, is make it so that, even if the player hit it near the top, it still tries to push them sideways.
I assumed I could take a “Vector3.one” and subtract its Upwards vector, then multiply the direction by that (Or lerp it for a milder effect) to essentially remove or minimize the upward force added to the player, making it so Vector Forward, and Vector Right have more of an influence.
Currently, the code here doesn’t do anything other than bounce with normal force in all directions. A Bias of 0 - 1, has no effect. I am unsure why this doesn’t work, but perhaps someone has another idea on how to calculate my “Bias” variable (The true force direction with the Up Vector masked out).