Skip to main content
10 events
when toggle format what by license comment
Mar 26, 2022 at 23:23 comment added mike Oh wow thanks that's very simple I get it now. Thanks again.
Mar 26, 2022 at 21:20 comment added DMGregory It's just the unit circle. kickDirection is in the horizontal plane, so it's the "adjacent" side of our triangle. Vector3.up is perpendicular to this plane, so it's the "opposite" side of our triangle. So to get a hypotenuse of length 1, elevated above the horizontal by angle, we need the length of the adjacent side to be the cosine of angle, and the length of the opposite side to be the sine of angle.
Mar 26, 2022 at 21:08 comment added mike Okay. lol at me. :) Yes. Pythagorean math. I spent the past 30 min drawing triangles while trying to re-derive your equation for educational purposes but failed. I am not good enough at this math. I know sin(theta) = opp/hyp, cos(theta) = adj/hyp, tan(theta) = opp/adj and I can see you are adding a small amount to the vertical while subtracting a bit from the horizontal. If you're willing to share a bit on the basic math for how that works or was derived to maintain the same vector length like that I would be curious. Otherwise no worries. Thanks for the help and instruction either way.
Mar 26, 2022 at 20:31 comment added DMGregory Completely unsound. This says "Rotate the vector 20 degrees around the world Z axis, then rotate the result 20 degrees around the world X axis". So if your direction was left (-1, 0, 0) then you end up tilting it downward by 20 degrees, then backward by another 20 degrees. What you could do instead is kickDirection = kickDirection * Mathf.Cos(angle) + Vector3.Up * Mathf.Sin(angle)
Mar 26, 2022 at 20:27 comment added mike One simple follow up: How would you go about angling up the kick, say by 10-20 degrees? The kickDirection would need to be rotated on the x/z axes to allow this. Is kickDirection = Quaternion.Euler(20, 0, 20) * kickDirection; logically or mathematically sound?
Mar 26, 2022 at 20:10 vote accept mike
Mar 26, 2022 at 20:05 comment added mike That's absolutely perfect. Thanks for the good summary. I realized you could not use Quaternions as I did but I did not understand how they worked or the correct method to do this. Thanks for explaining both. My app is for mobile so everything will eventually be controlled by custom UI Element touch buttons. So I will likely avoid the Unity Input Manager. I wasn't aware of Input Events. I have been using actions like public event Action runButtonFunction in my custom buttons class. I'm not sure if there is any extra utility in InputEvent. If you have any thoughts I'd be curious to listen.
Mar 26, 2022 at 12:34 history edited DMGregory CC BY-SA 4.0
Clarifying why quaternions/angles are unnecessary here
Mar 26, 2022 at 12:28 history edited DMGregory CC BY-SA 4.0
added 50 characters in body
Mar 26, 2022 at 12:22 history answered DMGregory CC BY-SA 4.0