# Arrow Physics

I’m trying to create a game where you shoot arrows. Up til now I have created posibility of shooting arrows, but they only have basic physics. Sure, they get dispensed into the air, but they dont fall like arrows. Arrows tip should fall first. I have created box collision shape and rigid body control, and added it to the arrow spatial which has loaded arrow model. I understand the problem, but dont have the solution. Should I create two box collision shapes, one as arrow body, and the other as the tip, and then set the tips mass bigger than the bodys, how should I link them, and then add the spatial model. Or should I get the contact point and then update rotation so arrow is faced towards the contact point? I probably could do the contact point bit, but I dont know how to make arrow parts have diffrent masses. Also now when I make the curent box collision shape too small it falls thru the floor.

The reason arrows fall head first is not because the parts have different mass, see http://en.wikipedia.org/wiki/Newton’s_laws_of_motion
It is because of air-resistance and aerodynamics. Which you will have to simulate yourself since there is nothing like that in the bullet library.

Personally I would try to simulate the arrow using a simple sphere, when that collides with something I would consider the arrow has hit. Then I would try to find some way to render the arrow with the arrow head at the center of the sphere and try to use the linear velocity vector to orient the
arrow.
I’m sure there are many other ways, perhaps someone has a simpler idea.

Yes, the flights at the back of the arrow are there for just this reason. They stabilize the arrow in flight and keep the pointy end pointing forwards.

Tnx for the help. Pls if someone has more ideas just post. Its strange how unexploited this subject is. Its like I’m the only one who enjois shooting things with arrows? XD
Seriously, Its weird.

I’m very interested as I’ve been planning to do this for my first game too, just haven’t had any time to do or try anything yet anyways, I’ve just thought about this a little and I’m not sure if it’s a good way, or even possible, as I haven’t done a thing with physics yet, but an arrow basically follows a certain line with its point because it gets stabilized. Meaning that the arrow’s point kinda points to where its going to. Meaning it’s rotation would be as much as the angle has changed in a specific amount of time

I think that you could do something like this to rotate it correctly:

iteration #1 in update loop -> save location of arrow to a var called oldLocation
iteration #2 in update loop -> calculate angle by doing: (current location of the arrow).substract(oldLocation) and store it into a var called oldAngle, also store the current location of arrow into oldLocation
iteration #3 in update loop -> now calculate the new angle like done in iteration #2, substract the oldAngle from it and rotate the arrow by that amount, then save the angle you calculated earlier in this iteration as oldAngle and repeat this iteration until you hit an object. Then stop rotating the arrow at all and let physics do its job…

EDIT:
Just read your post, hadn’t seen it before as I was probably typing the above but yeah it’s kinda strange…in general I can’t find a game with cool archery in it at all though Guess most people are more into guns haha

Note that it isn’t really soley to do with the fletching either… since arrows without fletching will still travel in a nice arc if you can get them to fire straight (like from a crossbow or throwing a javeline). Also, if you drop an arrow horizontally from about waist high it will hit the ground on its side. There just isn’t enough air resistance in that case to matter over a short distance. At high speeds the flights will provide a nice drag but that’s more because the arrow is really unstable coming off of the bow. Crossbows fire the bolts really straight so they can get away with little to no fletching. The flights help, surely but they are not real cause of the arcing effect.

Even bullets will travel this way if you fire them on an arc trajectory. (Note: bullets are really short so other factors also come into play… velocity, spin, etc.) (Interesting to note, though: if you fire an arrow straight up then it will come down head first… a bullet will come down sideways.)

So if that’s the effect you are going for then it might best just to simulate it. The tip of the arrow is ahead of the tail… so it will be farther along on the parabola than the tail. You could probably simulate the front and the back of the arrow separately with a rigid link of some kind but it seems like overkill to me. Of course it would let you put extra drag on the tail. You still might be able to simulate as an impulse or force applied to a point on the tail of a cylinder mesh. I’m not familiar enough with bullet to know how nice that is. Drag is a force so should be doable.

…I will hit this same problem soon in my own physics engine.

Actually, the more I think about it… a little bit of drag on the tail would be pretty easy and simulate the flights nicely. It would never work for a javelin but for arrows it would be fine.

I would not simulate the whole head, body and feathers. Why not just force the arrow to be parallel to it´s direction of travel? That way you only simulate your translational physics, and simply calculate the orientation based on a normalized velocity vector ( direction of travel ).

I think other games does it like this too. Try to shoot an arrow very weakly in Skyrim ( like flying half a meter ), and you will notice that the arrow, sort of turns unnaturally 90 degrees and falls to the ground head first.

Edit: You can use Quaternion.lookAtDirection() to calculate the orientation.
Edit #2: For collisions I would just use a line collision from head to tail of the arrow. Checking collisions only for the head is dangerous if you are moving the arrows quickly, as they could pass through the target in one time step, unless you are substepping your physics. A line segment, is much longer than the head of the arrow, and much faster and simpler than a mesh / mesh collision.

<cite>@nihal said:</cite> I would not simulate the whole head, body and feathers. Why not just force the arrow to be parallel to it´s direction of travel? That way you only simulate your translational physics, and simply calculate the orientation based on a normalized velocity vector ( direction of travel ).

I think other games does it like this too. Try to shoot an arrow very weakly in Skyrim ( like flying half a meter ), and you will notice that the arrow, sort of turns unnaturally 90 degrees and falls to the ground head first.

Edit: You can use Quaternion.lookAtDirection() to calculate the orientation.
Edit #2: For collisions I would just use a line collision from head to tail of the arrow. Checking collisions only for the head is dangerous if you are moving the arrows quickly, as they could pass through the target in one time step, unless you are substepping your physics. A line segment, is much longer than the head of the arrow, and much faster and simpler than a mesh / mesh collision.

Yeah that’s basically what I’m doing in my example aswell, I think physics for the location would be enough indeed.

You could also interpolate the angles you get a little bit, so you don’t get the effects of making those weird turns you are talking about. Or take the results from a few steps back and use those angles (referring to my earlier example)

Arrows have a very interesting physics, they wobble in flight.
See http://www.youtube.com/watch?v=ZJoTXRQNDPA&t=53 for a modern-day high-tech arrow on a high-tech bow, designed to minimize that wobble.
For “very old wood target arrows shot from a very old youth compound bow”, see http://www.youtube.com/watch?v=Ms4uTb5zkVI&t=36

Most games will do fine without that bending
You can apply a backwards-pointing force to the arrow. Attach one force to the tip, one to the tail. Let the tip one depend only on speed (proportional to square of speed if you want to get a realistic flight curve), add the same force with an (1.0f+sin(alpha)) factor to the back end where alpha is the angle that the arrow deviates from the trajectory. (You can avoid the sine by some clever vector manipulation, but I don’t have the formulae for that handy.) Make the force a bit larger while alpha is increasing to dampen the oscillation.
Have fun with arrows that will half-realistically flip around and scatter after they hit a target that they can’t penetrate

<cite>@nihal said:</cite> Edit #2: For collisions I would just use a line collision from head to tail of the arrow. Checking collisions only for the head is dangerous if you are moving the arrows quickly, as they could pass through the target in one time step, unless you are substepping your physics. A line segment, is much longer than the head of the arrow, and much faster and simpler than a mesh / mesh collision.

Or enable CCD in bullet.

Well tnx. Got the idea. Just need to get the latest location of the arrow and then rotate tail of the arrow towards it. Its so simple. How didnt I think of that!

Hm i would just attach a small invible mass at the back of the arrow with a slightly higher lineardampening, that should work out most of the stuff.
(For pro version, change the linear dampening based on velocity of the main body)

For almost all game related cases this should work quite nice, (or at least I see no flaw in it).

@Empire Phoenix said: (For pro version, change the linear dampening based on velocity of the main body)

Heheh… = drag.

I’d get rid of your whole idea of using bullet physics and instead use Motion paths (https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:motionpath).

the start point of the path would be the players location. you could use picking/ray casting to determine the end point of the motion path. Then use whatever points you want for the “inbetween” points so that it wil fly in whatever way you think looks most appropriate for your game. Besides automaticaly animating your arrows translations based on your own path, it has the built in ability to automatically rotate the arrow int he direction of the path.

If the rest of your game is physics based and you want to test for a collision, you could add a ghost control to the arrow and use that to check for collisions. The alternative woudl be using bounding boxes to check for collisions. Both methods have their pros and cons, I’d consider both alternatives and the implications of going either way.

…but if he comes up with a nice physics-friendly way of dealing with it then he won’t have to do any of that. And then the arrow will bounce nicely, etc…

Adding a little drag (however implemented) to the arrow should not be tough and is the simplest of all approaches… even manually adjusting the arrow angle to match current velocity is close.

I need help again. XD
I’m able to save the latest position, but Im not sure how to turn tail of arrow towards it. I tried this.
arrow.lookAt(arrow_latest_point, Vector3f.UNIT_Y);
arrow.rotate(3.14f, 0, 0);

<cite>@koljo45 said:</cite> I need help again. XD I'm able to save the latest position, but Im not sure how to turn tail of arrow towards it. I tried this. arrow.lookAt(arrow_latest_point, Vector3f.UNIT_Y); arrow.rotate(3.14f, 0, 0);
Have you tried rotating the arrow by currentAngle.substract(previousAngle), like I tried to explain in my first post on this thread?

EDIT:
<span style=“text-decoration:line-through;”>And you’re trying to rotate it 360 degrees? Shouldnt that be half pi if you want to flip it?</span>

EDIT2:
NVM my fail xD

EDIT3:
btw. I think you have to use setPhysicsRotation(arrow.getLocalRotatioon()); aswell. I’m not sure if its the way to go after all…seems a bit weird to mess with physics like that :\

Tnx for help everyone. I did it, but wouldn’t be tiping this if I didnt need more help. When I fire an arrow it flies ok(in an arc, like I’ve been trying to do), but when I fire another one while the first is in mid air, the first one doesnt fly in an arc anymore(the rotation for it stops updating). I update arrow rotation in the update loop. So, how am I supposed to update rotation so that its updated for all of the fired arrows?

<cite>@koljo45 said:</cite> Tnx for help everyone. I did it, but wouldn't be tiping this if I didnt need more help. When I fire an arrow it flies ok(in an arc, like I've been trying to do), but when I fire another one while the first is in mid air, the first one doesnt fly in an arc anymore(the rotation for it stops updating). I update arrow rotation in the update loop. So, how am I supposed to update rotation so that its updated for all of the fired arrows?
I'm pretty sure that you have to create a custom Control (https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_controls) in which you add the behaviour of the arrow (also put all the physics related stuff in there). Those controls are hooked into the main update loop. Create a new instance of the control and add it to the Spatial, that way the behaviour will be individual for each arrow fired.
2 Likes