Hello,
I was wondering if anyone could help me with my bullet functions. All the variables are declared Global. The thing is that when the player presses spacebar the CreateBullet function is called. The new bullet entity is placed in front of the player and made to face in the same direction as the player. This is done by using a temporary Pivot entity in front of the player and then using PointEntity to point the bullet at the player. The DoBullet function moves the bullet forward and then destroys it at certain distance.
However, when I use this code I only see the first bullet fired. Also, the bullet always heads in the same direction, even if the player is looking another way.
The player consists of three entities, the camera, the player mesh and a pivot between them (called "pivot" in the code which acts as the parent.
Could anyone give me a hint?
{code}
Function CreateBullet()
bullet = CreateCube()
temp = CreatePivot ()
PositionEntity temp, EntityX(pivot)+5,EntityY(pivot),EntityZ(pivot) +5
PointEntity bullet, temp
bullet_dist = 0
EntityRadius bullet,1
EntityType bullet,4
bullet_exist = True
End Function
Function DoBullet()
If bullet_exist
MoveEntity bullet,0,0,player_speed#+1
bullet_dist = bullet_dist+1
If EntityCollided (bullet, 3)
FreeEntity bullet
bullet_exist = False
End If
If bullet_dist = 60
bullet_dist=0
FreeEntity bullet
bullet_exist=False
End If
End If
End Function
{/code}
I was wondering if anyone could help me with my bullet functions. All the variables are declared Global. The thing is that when the player presses spacebar the CreateBullet function is called. The new bullet entity is placed in front of the player and made to face in the same direction as the player. This is done by using a temporary Pivot entity in front of the player and then using PointEntity to point the bullet at the player. The DoBullet function moves the bullet forward and then destroys it at certain distance.
However, when I use this code I only see the first bullet fired. Also, the bullet always heads in the same direction, even if the player is looking another way.
The player consists of three entities, the camera, the player mesh and a pivot between them (called "pivot" in the code which acts as the parent.
Could anyone give me a hint?
{code}
Function CreateBullet()
bullet = CreateCube()
temp = CreatePivot ()
PositionEntity temp, EntityX(pivot)+5,EntityY(pivot),EntityZ(pivot) +5
PointEntity bullet, temp
bullet_dist = 0
EntityRadius bullet,1
EntityType bullet,4
bullet_exist = True
End Function
Function DoBullet()
If bullet_exist
MoveEntity bullet,0,0,player_speed#+1
bullet_dist = bullet_dist+1
If EntityCollided (bullet, 3)
FreeEntity bullet
bullet_exist = False
End If
If bullet_dist = 60
bullet_dist=0
FreeEntity bullet
bullet_exist=False
End If
End If
End Function
{/code}