Hi all I am trying to draw my 3D enemy each time I call the enemy class at random position , but without success
That is my drawing code:
At this line Matrix.CreateTranslation(position); position is Vector3 an the argument in it are always random:Code:if ((texture != null) && (texture.Meshes.Count > 0)) { Matrix[] transforms = new Matrix[texture.Bones.Count]; texture.CopyAbsoluteBoneTransformsTo(transforms); foreach (ModelMesh meshh in texture.Meshes) { foreach (BasicEffect effect in meshh.Effects) { effect.EnableDefaultLighting(); effect.World = transforms[meshh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(position); effect.View = Matrix.CreateLookAt(new Vector3(0.0f, 50.0f, 5000.0f), Vector3.Zero, Vector3.Up); effect.Projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f); } meshh.Draw(); } }
But when I call the class 3 times I get 3 models at same coordinates.Code:Microsoft.Xna.Framework.Vector3 position = new Microsoft.Xna.Framework.Vector3(random.Next(0, GraphicsDevice.Viewport.Width), random.Next(0,300),1000.0f); Enemy eninit = new Enemy(secondModel, position, 100, 100, 0.5f);
This is the whole idea:
But there is one difference now everything on the above picture is 3D !






Reply With Quote