1

I've been trying to code a 3D game where the player shoots an arrow and I wanted to do the equations for the 3D. I know the equations for the 2D world where:

x = v0 * cosθ * t
y = v0 * sinθ * t - 0.5 * g * t^2

But how do I use these equations in my 3D world where I have the Z axis?

Spektre
  • 49,595
  • 11
  • 110
  • 380
Haytham95
  • 11
  • 1
  • You will need to figure the *direction vector*. Then for the 3rd coordinate (z?) It is similar to X. – Antti Haapala -- Слава Україні Aug 04 '19 at 22:11
  • Notice that the cosθ, sinθ is just the 2d unit vector rotated theta degrees from the X axis – Antti Haapala -- Слава Україні Aug 04 '19 at 22:13
  • see [Newton D'Alembert and vector math](https://stackoverflow.com/a/46110339/2521214) but as I mentioned in the other comment arrows have much more than just linear air friction and gravity going on ...My 35 lb long bow shoots ~137 km/h so you can use that as starting velocity for you arrows +/- over/under draw. But real bow aiming is not changing the speed but angles ... (initial direction) – Spektre Aug 04 '19 at 23:26

1 Answers1

1

Instead of making the arrows follow an explicit curve, I suggest simulating the arrow step by step.

What you need to store is a position (with x,y,z coordinates, starting off at the archer's location) and a velocity (also with x,y,z coordinates, starting off as some constant times the direction the player is looking), and some scene gravity (also with x,y,z coordinates, but it'll probably point straight down).

When the simulation progresses by a timestep of t, add t times the velocity to the position, then add t times gravity to the velocity.

This way, you're free to do more interesting things to the arrow later, like having wind act on it (add t times wind to the velocity) or having air resistance act on it (multiply velocity by t times some value a bit smaller than 1) or redirecting it (change velocity to something else entirely) without having to recalculate the path of the arrow.

Magma
  • 566
  • 2
  • 8
  • Footnote: technically the air resistance model isn't accurate, since the arrow should decelerate proportionally to the square of its velocity. – Magma Aug 04 '19 at 22:18
  • Arrows has dynamic wings and bendy-core (spin) making this a lot more complicated differential ... allowing the arrows to do much more complicated 3D curve (usually with helix with 2 superimposed rotations and or sin wave like trajectory) – Spektre Aug 04 '19 at 23:12
  • 2
    Let's not overdo it. – Magma Aug 04 '19 at 23:19