Sign in to follow this  
  • entries
    44
  • comments
    44
  • views
    36730

repost

Sign in to follow this  
nordwindranger

272 views

the icon for today is... green santa man?

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?
Sign in to follow this  


2 Comments


Recommended Comments

Are you perhaps shooting at where the ship was in the last frame, rather than where it will be?

You can tell you come from C++ looking at this code :D (only because of the capitalize style :D)

Share this comment


Link to comment
well I dabbled in basic, visual basic, java applets, c, and c++ before settling on c#. I don't remember where I picked up that particular quirk, but your right it was probably one of the c++ books that I read :)

As far as the firing code goes... I really have no idea what the problem is. Ships are firing at where their targets were, but as ships are slow, and lasers are fast, this hasn't been a big problem so far.

It's more like everything is right, but one of the coordinates need to be reversed. For example, if I make facingdirection.x negative, ships will hit their targets if they are in front of them, but if the targets are behind the ships, or too far off to the side, the ships will shoot in the opposite direction. I'm thinking that I'm going to have to rig up some system to handle this by selectively making coordinates positive or negative, but it really doesn't make sense. I shouldn't have to do this.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now