No problem. It is difficult for everyone at first
Try this:
_moveBullets:
IF CURRENT_BULLET >50 THEN CURRENT_BULLET = 1
DEC TIME
FOR T= 1 TO 50
IF SHELL(T).FIRED = 1
` check whether if bullet was and is moving
if SHELL(T).BULLETMOVING = 1
`set Y linear velocity to zero every loop so that it will not be affected by gravity
phy set rigid body linear velocity SHELL(T).bulletObject,phy get rigid body linear velocity x(SHELL(T).bulletObject),0,phy get rigid body linear velocity z(SHELL(T).bulletObject)
endif
` check whether it was fired and moving. This variable will be used to apply the one time force and to show it
if SHELL(T).BULLETMOVING = 0
`if no
SHOW OBJECT SHELL(T).bulletObject `show it
phy make rigid body dynamic box SHELL(T).bulletObject `setup as dynamic box
`apply force according to player angle.
phy add rigid body force SHELL(T).bulletObject, sin(player.playerCursorAngle)*10, 0, cos(player.playerCursorAngle)*10, 1
`now bullet is moving therefore set it as one. Remember to set it as zero when you recycle the bullet
SHELL(T).BULLETMOVING = 1
endif
SHELL(T).RANGE = SHELL(T).RANGE - 1
IF SHELL(T).RANGE <= 0 THEN SHELL(T).FIRED = 0 : SHELL(T).ALIVE = 0
ELSE
HIDE OBJECT SHELL(T).bulletObject
POSITION OBJECT SHELL(T).bulletObject,SHELL(T).START_X_POS,SHELL(T).START_Y_POS,SHELL(T).START_Z_POS
YROTATE OBJECT SHELL(T).bulletObject,SHELL(T).Y_ANGLE
ENDIF
NEXT T
fOR T= 1 TO 50 ` MAKE SURE THAT BULLETS AIM THE RIGHT WAY AND START AT THE CORRECT COORDINATES
SHELL(T).START_X_POS = OBJECT POSITION X(player.playerObject)
SHELL(T).START_Y_POS = OBJECT POSITION Y(player.playerObject)
SHELL(T).START_Z_POS = OBJECT POSITION Z(player.playerObject)
`position the bullet outside the player using trigonometry to not trigger collision
SHELL(T).START_X_POS = playerXPos# + (sin(player.playerCursorAngle))*1.6
SHELL(T).START_Y_POS = playerYPos#
SHELL(T).START_Z_POS = playerZPos# + (cos(player.playerCursorAngle))*1.6
SHELL(T).Y_ANGLE = player.playerCursorAngle
NEXT T
RETURN
For this to work you need to insert in the Bullet type another variable named BULLETMOVING.
There are comments for everything I added but the most important changes I made were:
- change bullet placing to be outside object so there is no collision with player
- applied force using trigonometry, so that it will move according to the player direction
- set the y linear velocity to 0 every loop, so that it will not be affected by gravity.
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why.
Programmers combine theory and practice: Nothing works and they don't know why.