Bullets hitting backwards?

Blitz3D Forums/Blitz3D Programming/Bullets hitting backwards?

mr.ninja(Posted 2004) [#1]
hello.
I have a spaceship flying and shooting (3rd person view).
I have some enemies that collide with it (as asteroids).

the problem is that sometimes, when the enemies are really close to the back of the spaceship, a bullet shoots backwards hitting the enemy, as if it is an homing missile, and the strange thing is that the enemy is immediately destroyed instead of taking the specified amount of damage...

anybody has any clue?

thanks
Paolo


Ross C(Posted 2004) [#2]
Make sure your bullets are coming out of the front of the ship, and not being generated at the back of it and moving forward :)


mr.ninja(Posted 2004) [#3]
Thanks. That could be the problem.

But I'm not really sure how I can generate the bullets in the front. the code is:

Function createbullet(ship)
b.bullet=New bullet
b\ent=CopyEntity (main_bullet)
b\x=EntityX(ship)
b\z=EntityZ(ship)
b\y=EntityY(ship)
PositionEntity b\ent,b\x,b\y,b\z
TurnEntity b\ent, EntityPitch (ship), EntityYaw (ship), 0
b\speed=ShotSpeed
b\time=ShotLife
b\timer=MilliSecs()
End Function

"ship" is a pivot that is moved (with keystrokes and mouse), but if I try to attach my bullets to anything else (such as another parented pivot) they don't move with the ship. Moreover, if I just try to put:

b\z=EntityZ(ship)+5

to move the bullet starting point towards the front of the ship, then the bullets startint position get screwed as soon as I turn the ship (i.e. they get fired from some point to the left or the right of the ship)...

Anyway I noticed that some of the bullets gets also fired sideways, as if they are attracted by the enemy entity...


Shambler(Posted 2004) [#4]
Put a pivot in front of your ship, point it away from the ship so it is looking in the direction of firing and then parent that pivot to the ship.

This way you always know what direction is 'forward' and you can fire your bullets from this pivot's position.


Ross C(Posted 2004) [#5]
Well, do you generate the bullets when the user presses fire? If so then position the bullet at the ships co-ords, rotate the bullet to the ships rotations(entitypitch etc), then use the command, moveentity b\ent,0,0,1.

That will move the ship forward one unit, in it's orentation :)


mr.ninja(Posted 2004) [#6]
Thanks all.
I can now set the starting position of the bullet, but the problem is still there. If I keep the fire button pressed I can actually see, sometimes, a bullet flying "out of the line" and pointing directly towards the enemy.

It happens when I move the ship (if I turn, or if I decrease the speed).

Paolo


MSW(Posted 2004) [#7]
parent the bullet on creation to the ship pivot...this will automaticly place it and point it in the right direction (no need to further rotate it)...set your shotspeed, and timers...then parent the bullet to the world (this way it's movements arn't locked in relation to the ship)...


Bot Builder(Posted 2004) [#8]
one problem might be your using turnentity instead of rotateentity. Ic guess it does the same thing if it starts from 0,0,0 but I would't be to sure.


mr.ninja(Posted 2004) [#9]
thanks, looks like now it's ok. I have the shot generating from an alpha 0 sphere (I still cannot have it to work with a pivot) in the front of the ship, and I used rotateEntity instead of turnEntity.
I'll have to test it a bit more, though, just to be sure it's ok...

Paolo


Jeppe Nielsen(Posted 2004) [#10]
You could also do this, without using a pivot:
Function createbullet(ship,distancetofront#=1) 
b.bullet=New bullet 
b\ent=CopyEntity (main_bullet)
Tformpoint 0,0,distancetofront,ship,0
b\x=tformedx()
b\z=tformedy()
b\y=tformedz()
PositionEntity b\ent,b\x,b\y,b\z 
RotateEntity b\ent, EntityPitch (ship), EntityYaw (ship), EntityRoll(ship)
b\speed=ShotSpeed 
b\time=ShotLife 
b\timer=MilliSecs() 
End Function