quick and dirty jetpack mod

Topics: User Forum
Dec 21, 2006 at 8:17 PM
Awesome project you have here Clyde. In order to get a better vantage point of the landscape, I modded the code in Game1.cs of the TestQuadtree1 project.

First push out how far the camera looks in the Z direction (line 45):
Vector3 cameraReference = new Vector3(0, 0, 1000);

Next in the UpdateAvatarPosition function, add a new block to handle the spacebar creating a jetpack boost effect. (I added this code right after the blocks handling the up and down keys) (line 297):
if (keyboardState.IsKeyDown(Keys.Space))
Matrix forwardMovement = Matrix.CreateRotationY(avatarYaw);
Vector3 v = new Vector3(0, speed, 0);
v = Vector3.Transform(v, forwardMovement);
avatarPosition.Y += v.Y;

And finally we need to modify what the camera looks at so that we can see the lay of the land as we climb. Add this code to the UpdateCameraFirstPerson function right after Vector3 cameraLookat gets set (line 365):
cameraLookat.Y = quadtree.GetHeightAt(cameraPosition.X, cameraPosition.Z) + avatarHeadOffset.Y;

Because of the physics coded into the demo, you need to hold shift+spacebar to get really high.
Dec 21, 2006 at 8:46 PM
Thanks chavo1, I'll incorporate this into the demo :)