Adding direction to bullet instance

Dec 11, 2012 at 7:52 AM

Hey all,

I'm puzzling with the shooting system for quite some time now.
The thing is, I want to be able to shoot in a direction.

The problem is that the bullet may not change it's direction when it has been shot.

So how can I add a direction to this piece of code (when instancing the bullet) ?

var bullet = new Instance() { Template = BulletTemplate };
                bullet.Transform = Parent.Transform;



Dec 11, 2012 at 10:00 AM

Just have so the bullet moves forward. So when you add a bullet you can just change the Transform of the bullet.

bullet.Transform = Matrix.CreateRotationY(MathHelper.ToRadian(90)) * Parent.Transform;

Dec 11, 2012 at 12:23 PM

Oh thanks, I think I know what the problem is.
I also have a Character which uses Parent.Transform:

var transform = Parent.Transform;
and it uses.
transform.Translation += Speed * elapsedTime * Vector3.Backward;  

I also put my BirdEyeCamera in this <Group>, so they move together.

Is there any 'nice' way to split the transforming of the camera and the player, from the transforming of the bullet? 

Dec 11, 2012 at 1:10 PM

If you put the bullet inside the scene, its transform is independent of the player. You scene tree should look like:



        <Camera />

        <Player />


    <Bullet />

    <Bullet />



Dec 11, 2012 at 1:13 PM

Great thanks!

I will try and adjust my Scene.

However, does the bullet shoot from my Player at this moment?
Because the Transform doesn't apply to the bullet when I walk around with my player I think... 

Dec 11, 2012 at 8:57 PM

Could I take a look at your code? But you don't have to post it here, You know how to contact me. :P