So I'm trying to shoot lazers in the direction a spaceship is pointing. Got that done... Although, I'm having trouble getting the positioning of the spawnpoint right and the speed. Here's some code:
Lazer setup:
//Lazers
SP_Lazer = CreateSprite ( LoadImage ( "Lazers/laserBlue06.png" ) )
SetSpriteSize ( SP_Lazer , 13 , 37 )
SetSpriteVisible ( SP_Lazer , 0 )
SetSpritePhysicsOn ( SP_Lazer , 1 )
Type LazerType
Sprite
Angle As Integer
Speed As Integer
Count As Integer
EndType
Dim Lazer[0] As LazerType
//Physics
SetPhysicsGravity ( 0 , 0 )
Lazer spawn:
//Lazers
If GetPointerPressed ( )
Lazer[0].Count = Lazer[0].Count + 1
Dim Lazer[Lazer[0].Count] As LazerType
Lazer[Lazer[0].Count].Sprite = CloneSprite ( SP_Lazer )
SetSpritePosition ( Lazer[Lazer[0].Count].Sprite , GetSpriteX ( SP_Ship[2].Sprite ) , GetSpriteY ( SP_Ship[2].Sprite ) )
SetSpriteVisible ( Lazer[Lazer[0].Count].Sprite , 1 )
Lazer[Lazer[0].Count].Angle = AtanFull ( GetSpriteXByOffset ( SP_Ship[1].Sprite ) - ( GetViewOffsetX ( ) + X# ) , GetSpriteYByOffset ( SP_Ship[1].Sprite ) - ( GetViewOffsetY ( ) + Y# ) ) + 180
SetSpriteAngle ( Lazer[Lazer[0].Count].Sprite , Lazer[Lazer[0].Count].Angle )
SetSpritePhysicsOn ( Lazer[Lazer[0].Count].Sprite , 2 )
SetSpriteShape ( Lazer[Lazer[0].Count].Sprite , 0 )
//SetSpritePhysicsMass ( Lazer[Lazer[0].Count].Sprite , 1 )
SetSpritePhysicsVelocity ( Lazer[Lazer[0].Count].Sprite , 0 - ( ( GetSpriteXByOffset ( SP_Ship[1].Sprite ) - ( GetViewOffsetX ( ) + X# ) ) * 10000000000 ) , 0 - ( ( GetSpriteYByOffset ( SP_Ship[1].Sprite ) - ( GetViewOffsetY ( ) + Y# ) ) * 10000000000 ) )
EndIf
Some information:
SP_Ship[2].Sprite is the gun sprite. (I build the players spaceship in parts.)
The gun sprite is positioned at a certain point on the ship and then given a offset so that it can rotate around the center point (the middle of the screen). It is positioned like this:
SetSpritePosition ( SP_Ship[2].Sprite , ( 960 - ( GetSpriteWidth ( SP_Ship[1].Sprite ) / 2 ) ) - ( GetSpriteWidth ( SP_Ship[2].Sprite ) / 2 ) , 540 - ( GetSpriteHeight ( SP_Ship[2].Sprite ) / 2 ) )
(SP_Ship[1].Sprite is the cockpit in the middle.) Setting the offset:
SetSpriteOffset ( SP_Ship[i].Sprite , 960 - GetSpriteX ( SP_Ship[i].Sprite ) , 540 - GetSpriteY ( SP_Ship[i].Sprite ) )
Rotating the entire ship. (within a for/next loop)
SP_Ship[i].Angle = AtanFull ( GetSpriteXByOffset ( SP_Ship[1].Sprite ) - ( GetViewOffsetX ( ) + X# ) , GetSpriteYByOffset ( SP_Ship[1].Sprite ) - ( GetViewOffsetY ( ) + Y# ) )
SetSpriteAngle ( SP_Ship[i].Sprite , SP_Ship[i].Angle )
(X# = GetPointerX();Y#= GetPointerY())
Moving the ship: (within a for/next loop)
SetSpritePhysicsVelocity ( SP_Ship[i].Sprite , 0 - ( GetSpriteXByOffset ( SP_Ship[1].Sprite ) - ( GetViewOffsetX ( ) + X# ) ) , 0 - ( GetSpriteYByOffset ( SP_Ship[1].Sprite ) - ( GetViewOffsetY ( ) + Y# ) ) )
SetSpritePositionByOffset ( SP_Ship[i].Sprite , GetViewOffsetX ( ) + 960 + ( GetSpritePhysicsVelocityX ( SP_Ship[i].Sprite ) / 20 ) , GetViewOffsetY ( ) + 540 + ( GetSpritePhysicsVelocityY ( SP_Ship[i].Sprite ) / 20 ) )
*The view offset is then set so that the ship is always in the dead center*
WHAT I WANT TO KNOW:
how can I change
SetSpritePosition ( Lazer[Lazer[0].Count].Sprite , GetSpriteX ( SP_Ship[2].Sprite ) , GetSpriteY ( SP_Ship[2].Sprite ) )
so that it spawns right infront of the SP_Ship[2].Sprite?
No matter how many zeros are added here (I've gone overboard to test) the lazers don't go faster.
SetSpritePhysicsVelocity ( Lazer[Lazer[0].Count].Sprite , 0 - ( ( GetSpriteXByOffset ( SP_Ship[1].Sprite ) - ( GetViewOffsetX ( ) + X# ) ) * 10000000000 ) , 0 - ( ( GetSpriteYByOffset ( SP_Ship[1].Sprite ) - ( GetViewOffsetY ( ) + Y# ) ) * 10000000000 ) )
How can I make them faster? At the moment my ship can overtake them easily.
Hopefully you can understand! I'm a little tired so this might be a load of random information!
*New question down below*
cheers