models spawning in same position
Hi
I am having a problem I cant work out, and I am looking for some direction. I am trying to draw a list of 20 models and they are being to the screen but they are all being drawn to the game window at the exact same position and I cant see where my code is wrong,
In my enemy class I have
public Enemy(Game1 game)
{
randX = random.Next(1, 10);
randY = random.Next(1, 10);
randZ = random.Next(1, 10);
enemyPos = new Vector3(randX, randY, randZ);
enemyColBox = new Box(enemyPos, 3f, 3f, 3f);
enemyModel = new EntityModel(enemyColBox, game.Content.Load<Model>("Models/enemyShip1"), Matrix.Identity * Matrix.CreateScale(0.03f), game);
hit = game.Content.Load<SoundEffect>("Audio/Hit");
game.space.Add(enemyColBox);
game.Components.Add(enemyModel);
enemyColBox.Tag = enemyModel;
}
Game class
protected override void LoadContent()
{
makeEnemies(20);
}
public void makeEnemies(int num)
{
for (int x = 0; x < num; x++)
{
enemy.enemyPos = new Vector3(enemy.randX, enemy.randY, enemy.randZ);
newEnemies.Add(new Enemy(this));
}
}
I'm not familiar with XNA, but are you properly seeding your random function? I found a problem similar to yours here, see if it helps.
Have you tried increasing the range of the random positions you generate (say 1 to 1000 instead of 1 to 10)?
It could be that they're all getting spawned at different locations, but because the range is so small it looks like they're all in exactly the same spot.
Seeding the random number generator is also a good idea.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement