Jump to content
  • Advertisement
  • entries
  • comments
  • views

View Mode implementation and wittering

Sign in to follow this  


Now I have a chase camera working that can be assigned to move to different targets, I've been working on a "view mode" for the player. Holding down the right-mouse button moves the camera to a shoulder-view mode so the player can look around.


Here I have put the camera in a position right behind the head, so that you can see in more detail that the orientation of the head changes to match the direction you are looking. You'll see this first in the video later, then it switches to the real shoulder-view mode which is just above the right shoulder but the head animation is less obvious.

To implement the head animation, I now generate my animation [font='courier new']KeyFrame[/font] inside the [font='courier new']PcStateMachine[/font].

void Pc::prepareScene(SceneParams ¶ms, float blend){ KeyFrame key = machine.generateKeyFrame(blend); data.animation.skeleton.setKeyFrame(key); // snip}We can then generate the key frame from the animation as usual, but apply further modifications to it before we return it.

KeyFrame PcStateMachine::generateKeyFrame(float blend){ KeyFrame key = data.animation.controller.keyFrame(blend, data.animation.map); if(curr == PcState::Looking) { key.transforms[data.animation.skeleton.index("Neck")].rotation *= axisRotationQuaternion(Vec3(-data.ang.value(blend).y, 0, 0)); } return key;}We can save time by looking up the "Neck" index ahead of time. Bone names are set in Charm, the model editor, and are stored as part of the binary model format to avoid working directly with numeric indicies. Here we just apply an extra bit of rotation to the neck based on the accumulated angle we are looking in, which is stored in [font='courier new']PcData::ang[/font], a [font='courier new']BlendVec2[/font].

So we can do whatever we want to here, depending on the current internal state of the [font='courier new']PcStateMachine[/font] and [font='courier new']PcData[/font].

The player rotates horizontally to match the angle you are looking at, and because the view down is limited, there is no need for a foot animation to show this turning action. When you release right button, the camera pulls back out and you are facing whatever direction you last looked in.

void PcStateMachine::updateLooking(GameState &state, float delta){ Vec2 a = data.ang.value(); a.x += pi(); data.rot = FadeValue(axisRotationQuaternion(Vec3(0, a.x, 0)));}As above, [font='courier new']PcData::ang[/font] is the accumulator for the angle the camera is looking in and [font='courier new']PcData::rot[/font] is a quaternion representing the direction the actual player is currently facing, so when looking, changing one updates the other.

Here is all of this in motion.

While this is a nice feature on its own for looking around in the game, it is also prepartion for the bow aiming mode I plan to tackle soon. When the player is holding a bow, view mode will include moving into a bow-drawn animation, and the arm will move with the head to point the bow at whatever point is looked at. Hopefully the position of the camera will mean I can get away with just a partial animation for aiming the bow, and the superimposing of an arrow mesh over the top. We shall see how this works out.

There are some issues at the moment with the camera intersecting the player model, and indeed have always been issues with the camera intersecting the level geometry that I haven't quite decided how to tackle yet. One approach might be to just model the camera as a sphere, and add the minimum separation vector for the sphere to the final camera position each frame but that could lead to some nasty jumps.

I don't really want to have to apply full path-finding logic to the camera. A possible solution might be to detect when the camera is jumping beyond a certain threshold and then apply a very fast fade-out/fade-in effect to cover the jump. Need to just try a few different approaches and see how they look.

Thanks, as always, for stopping by and I hope this was of interest to someone.

Sign in to follow this  


Recommended Comments

Thank you for the offering of plumbing services. I always prefer my plumbing services to be conducted in Arabic. Makes perfect sense to me. Who says the internet is a strange place?

[Edit] This made more sense before the spam comment was deleted :)

Share this comment

Link to comment
Wow @ both of you? But don't worry, I'm glad if there's even only one of you ha ha! This is something completely different than Squishy and quite a bit more complex. I don't know too much about 3D animation, but the idea about camera and adding the separation vector but with fade-out and -in over some threshold is just brilliant. Way to go!

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!