Cannonball

Blitz3D Forums/Blitz3D Beginners Area/Cannonball

kantuno(Posted 2014) [#1]
I am making a pirate game, and i have the ship working fine, but the problem comes when I make it fire the cannon. I dont know how to get the cannonball to move and keep moving. Here is my code for it:

If KeyHit(57) Then
cannon1 = CreateSphere()
PositionEntity cannon1,EntityX(testcube),EntityY(testcube),EntityZ(testcube)
RotateEntity cannon1,EntityPitch(testcube),EntityYaw(testcube),EntityRoll(testcube)
ScaleEntity cannon1,0.3,0.3,0.3
EntityType cannon1,cannon_col
EntityColor cannon1,50,50,50
MoveEntity cannon1,-1.5,0,0
EndIf

My problem is that it doesnt keep moving until it hits its target. If anyone can help with this I would be really grateful, i've been stuck on it for a while.


Who was John Galt?(Posted 2014) [#2]
The problem with your code is that you only move the cannonball once when you create it. You have to remember how many cannonballs are in play, and have some code to move them appropriately each frame. Start by investigating types in the B3D documentation. You need to create a cannonball type and create one of these when fire is pressed. Types are added to a list when they are created, so you can iterate over your cannonball list each frame and move each one.

If this confuses you, start as I said by reading up on types.


dynaman(Posted 2014) [#3]
The code above only runs once, the instant you press the '57' key. You need to have the key hit create a cannonball and then have another section of code check to see if cannonball exists and move it.

psuedocode.

if keyhit(57) then
cannon1 = createsphere()
...
end if

if cannon1 exists then
move the cannonball
end if