Bow and Arrow beginnings [updated]

Published November 05, 2016
Advertisement

I've been working a little bit on the view mode with the bow this week. Not spent a lot of time on it but Saturday morning seems to be a good time to update my journal since I have an hour to work on the game and can't really get into anything else properly, so we are only about half-way through this.

bowdraw.jpg

This is the camera view with the bow attached to the hand. The bow is just attached same as on my previous entry and there is a new animation to switch into when in this mode. Here it is set up in Charm, the model and animation editor.

charmbow.jpg

In motion, we apply the up/down rotation from the view to the Chest rather than the Head of the character now, which moves the arm as well as the head, meaning the bow continues to point where you look.



I should say I'm entirely unhappy with the quality of the graphics here. Need a much more detailed hand for example. I'm toying with the idea of using a different model for the view mode and normal mode, although that will present difficulties of its own so it may just be we have to suck it up and build a higher-resolution model for the player. The current model is very low poly, which is fine from a distance, but this was always just a stop-gap model anyway and not the final for any game.

I need to make a decision about the arrow. Do I attach it to the other hand, and move it into position using the draw animation, then use this to inform the initial transform of the arrow when it is "fired", or do I keep the arrow completely separate and just ensure by tweaking the bow animation that the arrow rests in the right place when being drawn back?

I can see pros and cons to both approaches really. One thing that is nice is that, either way, it will be trivial to swap out the bow and the arrow meshes for other ones, so once this is working it will be easy to have a sort of Thief/Thief 2 style bow and arrow system with different bows and arrows having different abilities and powers.

It is all a bit fiddly though. I'm going to live with the crappy graphics for now until I have the actual system working the way I want. I don't think my attachment system is working quite right and need to iron out some issues there - seems the initial transform I apply to the bow in object space is somehow causing some drift in the position when in aiming mode which must be a simple enough issue to find and fix.

Sure it will all come together in the end, and it will be very satisfying to fire that first arrow into the world.

[UPDATE]

Thought it wasn't worth a new entry for this, but I've added an arrow mesh now. Threw a very quick arrow model together in Charm.

arrow.jpg

I decided to go down the route of attaching the arrow to the other hand, so it can be guided into place using the animation. Took some fiddling around to get it right but seems to work okay.

The video below shows a special external view of the animation first, then switches to what you would actually see in-game, with the camera moving to the over-the-shoulder view.



It is actually two animations, one moving from idle to the bow drawn position, then another animation all in the bow drawn position with a tiny amount of breathing added. This is the further modified by applying a portion of the up/down rotation of the camera to the Chest bone of the player.

To get this working, I had to add a facility to my animation system to set an animation to looping or non-looping. They were all looping before, which was wrong here as it was switching briefly back to idle then back into bow drawn when the animation event fired on the EnterBowDrawn animation.

It was quite scary how little I could remember about how that code worked and was quite good to revisit it. Have used it extensively for a year or two, but not actually opened the source files in almost as long :)

So the theory is now that when the player presses the Fire key, we take the current matrix being applied to the player's arrow and pass this to a system that spawns an arrow to be fired off into the world.

This matrix should generate both the start transform of the new arrow as well as its movement vector, since we know the arrow is pointing straight down in local space, so transforming (0, -1, 0) by the matrix should give the direction vector for the arrow as well. You can just see the green line I've added to the below.

aimingline.jpg

Here we are taking the transform and using it to generate a vector from the tail end of the arrow ((0, 0, 0) in local space of the arrow model) and extending it out via a directional vector.

void Pc::prepareScene(SceneParams &params, float blend){ KeyFrame key = machine.generateKeyFrame(blend); // snip Matrix am = data.animation.skeleton.placementTransform(data.animation.skeleton.index("Right Hand"), identityMatrix(), world); arrow->setTransform(am); Vec3 d = transformNormal(Vec3(0, -1, 0), am); Vec3 p = transformCoord(Vec3(0, 0, 0), am); debugAddLine(p, p + (d * 4), makeColor(0, 255, 0));}We will on the same frame just hide the player arrow and we should be ready to go.

Need to design up some kind of inter-system communication for this that will extend to other things. Not sure on the details of this yet as I need to think about what else it is likely to be used for.

Thanks for stopping by as usual and hope this was of interest.

11 likes 2 comments

Comments

Alberth

Thanks for the blog update.

I looked first at the second video and then the first video (both very nicely made btw). What struck me with the latter is how the hand of the model doesn't actually hold the bow. I guess this is one of the things that need fixing with a better model.

Another thing I noticed with your second video is aiming. I am not sure how this works in reality, but with the few times I shot with a bow, you look alongside the arrow to see what it's pointing at. You normally don't point at the thing you want to hit, but above and aside from it (above to compensate for gravity, aside to compensate for wind). For longer distances, you would probably need some other device.

Also, you cannot hold a drawn bow and arrow steady. The tip of the arrow will dance around the target in your line of sight. Shooting is for a part letting go at the right moment :)

To see it, take a pen, hold it up at arm length, close one eye, and now try to make and hold a line of sight from your one open eye, over the top of the pen, to some small fixed point at the other side of your room (eg a corner point of a light switch, the top left of a book, whatever is at the other side of the room).

You will find you cannot hold your pen steady enough. With a bow and arrow, this is even worse, as there is a lot of tension required to just prevent the arrow from flying away.

Not sure if this is too much detail for your game, just thought I should mention it.

Oh, and please make some feathers on the arrow, it now looks like a spear :)

November 06, 2016 09:45 AM
Aardvajk
Thanks mate. Yes, all good points and things to improve once the basic system is working. I really appreciate the detailed input, thank you :)
November 06, 2016 11:51 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement