As it turns out, its fairly simple to make a nice space skybox. I just used paint.net (a free photoshop like application)to add some distortion to a black background. This ends up being a random distribution of dots, and I then used the lighting and contrast settings to make some of them stand out more.
I've decided that it is finally time to do something about my poor firing code, and after tinkering with it for a bit, I made a forum post in the "for beginners" section. Unfortunately it has gotten completely buried! I didn't realize that that forum was so busy... so here it is again, in case anybody reading this has any ideas:
Ships shoot beautiful streams of laser and ion shots, collision works perfectly, but ships can't aim to save their life. The only time my ships actually hit what they are shooting at is when their target is directly in front or behind them, and I have no idea why...
public void fireLaser(ship owner, ship target) { if (gunOffsetIndex > gunOffset.Count - 1) { gunOffsetIndex = 0; } rotationMatrix = Matrix.LookAtLH(owner.Position+gunOffset[gunOffsetIndex], target.Position, new Vector3(0.0f, 1.0f, 0.0f)); // Calculate the direction you're facing facingDirection = new Vector3(rotationMatrix.M31, rotationMatrix.M32, rotationMatrix.M33); facingDirection.Normalize(); allLasers.Add(new laser(20f,owner.Position+gunOffset[gunOffsetIndex],facingDirection,rotationMatrix,owner,target,owner.turbolaserStr)); gunOffsetIndex++; }public void render(Device device, Matrix world, Matrix view, Matrix proj, Effect effect) { //--------------------------laser rendering---------------------------------------------------------------- effect.Technique = "RenderPlain"; int passes = effect.Begin(0); for (int pass = 0; pass < passes; pass++) { effect.BeginPass(pass); foreach (laser b in allLasers) { Matrix laserMatrix = Matrix.RotationYawPitchRoll(b.facingDirection.X, b.facingDirection.Y, b.facingDirection.Z) * Matrix.Translation(b.position); effect.SetValue("worldViewProjection", laserMatrix * world * view * proj); for (int i = 0; i < laserTextures.Length; i++) { effect.SetValue("SceneTexture", laserTextures); effect.CommitChanges(); laserMesh.DrawSubset(i); } } effect.EndPass(); } effect.End();//other stuff...//and here is the "laser" update method public void update(float elapsedTime) { aliveTime += elapsedTime; //updates the bullets lifetime Vector3 dir = facingDirection; //getting the facing direction dir.Scale(elapsedTime * speed); // Now append that to the current position position += dir; }
heres a video
Usually when i post something here I am able to figure it out with a little push in the right direction, but I'm baffled on this one. I've went over all the code, and i don't think I'm doing anything wrong. Quite simply a vector3 that "connects" the two ships is calculated, and then the laser moves down that vector. what am i missing?
You can tell you come from C++ looking at this code :D (only because of the capitalize style :D)