I definitely do need some help!!
What I want:
I am trying to implement a 2.5D game like Mario Bros Wii. That is: A 2D Background scrolling from right to left and vice versa with a 3D player and 3D objects.
What I have:
I already have a 2D environment build up with tiles (see platformer example game of xna). In that I inserted a 3D Model, that moves and interacts with the world. Collision Detection and everything.. thats all fine!
What is my problem:
My problem is that the camera moves with the Player.. that is actually okay and what I wanted to. I did implemented it this way: Camera.Position = modelPosition. But what I dont want to is that it results in a relationship between the player camera and all the other object cameras. The result is that all the other objects move with the player. BUT they should stay in place and should only be passed by the player (or collected)..
Do you know what I mean??
What is my assumption:
The player moves along that 2D coordinate system and the camera position will be set to the player position..
If I put in another object (in sketch: o) as well (like something to collect) it will sit in a 3D coordinate system that sits in that 2D coordinate system. (see sketch) So the camera of that object moves with the actual camera. But never the less the position is (0, 0, 0)..
What can I do??
Example Player & Object:
o <>
/|\
|
/ \
If I move the player the object moves relative to it.
What is my code:
Player:
public void DrawPlayer()
{
Matrix[] bones = animationPlayer.GetSkinTransforms();
if (playerDirection == Direction.Left)
modelRotation = Math.Abs(modelRotation);
else
modelRotation = Math.Abs(modelRotation) * -1;
Matrix view = Matrix.CreateRotationY(MathHelper.ToRadians(modelRotation)) *
Matrix.CreateRotationX(MathHelper.ToRadians(0)) *
Matrix.CreateTranslation(modelPosition) *
Matrix.CreateLookAt(cameraPosition, modelPosition, Vector3.Up);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
foreach (ModelMesh mesh in player.Meshes)
{
foreach (Effect effect in mesh.Effects)
{
effect.Parameters["Bones"].SetValue(bones);
effect.Parameters["View"].SetValue(view);
effect.Parameters["Projection"].SetValue(projection);
}
mesh.Draw();
}
}
Camera:
public void Update(GameTime gameTime)
{
position.X = -Player.ModelPosition.X;
position.Y = Player.ModelPosition.Y;
}
Pizza (Object):
public void Draw(GameTime gameTime)
{
Matrix[] transforms = new Matrix[pizza.Bones.Count];
pizza.CopyAbsoluteBoneTransformsTo(transforms);
//float temp = Camera.Position.X / (1280 / 2);
//CamTranslation = Matrix.CreateTranslation(new Vector3(xpos, 0, 0));
foreach (ModelMesh mesh in pizza.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.World = transforms[mesh.ParentBone.Index] *
Matrix.CreateRotationY(modelRotation)
* Matrix.CreateTranslation(modelPosition);
effect.View = Matrix.CreateLookAt(cameraPosition,
Vector3.Zero, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45.0f), aspectRatio,
1.0f, 10000.0f);
}
mesh.Draw();
}
}