- Home /
Rotating a Vector direction by another Vector direction in one axis
Hi, I have been trying to work this one out for a while now and am starting to get Vector poisoning. I have tried many different solutions but to no avail. I am trying to take the product direction of a Vector3.Reflect which I use to make a ball bounce off the floor, but I also want the play to be able to steer when they bounce off the floor, so I have a Vector that is the balls moving position but rotated according to the input by the player. I want to combine these when the ball bounces so that it produces a bounce vector that has been rotated by the players input. Here is a image of what I'm trying to achieve;
When usually getting the turn rotation I just do this Vector3 NewRot = new Vector3 (ParRot.x, ParRot.y += (rot * (BaseRotSpeed*5)), ParRot.z);
The ParRot is basically just the current objects rotation. But if I try to combine this with the Bounce vector it affects the vertical speed Vector3 NewRot = new Vector3 (bounceV.x, bounceV.y += (rot * (BaseRotSpeed*5)),bounceV.z);
Just getting a normal bounce is like this; private void FloorBounce (float rot, Vector3 bounceV, float forcemulti) { Quaternion BounceDirection = Quaternion.LookRotation (bounceV); Vector3 bouncedir = bounceV * V.magnitude; Parent.transform.rotation = BounceDirection; ThisRB.velocity = new Vector3 (bouncedir.x * 0.95f, bouncedir.y * forcemulti, bouncedir.z * 0.95f); }
with bounceV being the Vector3 reflect vector. I have tried doing something like this and got quite close;`bounceV = Quaternion.AngleAxis(ParRot.y += (rot*10), Vector3.up) * bounceV;` or this Quaternion BounceDirection = Quaternion.LookRotation (Quaternion.AngleAxis(NewRot.y - bounceV.y,Vector3.up) * bounceV);
But to no avail, please anyone who knows their vectors and Quaternions I could really use your help, thank you!
$$anonymous$$aybe my two vectors are at different orientations, one being from a Reflect and one being a Euler of the objects rotation??
Answer by Symons · Apr 02, 2018 at 12:56 PM
Ok realize I could just cheat it like this, so much easier :D
private void FloorBounce (float rot, Vector3 bounceV, float forcemulti)
{
Vector3 newBounceV = Quaternion.AngleAxis(rot*10, Vector3.up) * bounceV;
Quaternion BounceDirection = Quaternion.LookRotation (newBounceV);
Vector3 bouncedir = newBounceV * V.magnitude;
Parent.transform.rotation = BounceDirection;
ThisRB.velocity = new Vector3 (bouncedir.x * 0.95f, bouncedir.y * forcemulti, bouncedir.z * 0.95f);
}