throwing a bomb

Blitz3D Forums/Blitz3D Programming/throwing a bomb

Blitzplotter(Posted 2007) [#1]
Hi. I recently managed to chuck a bomb in an arc, with a trajectory. My problem is it only throws directly north. I would like to through it in the direction I am looking.

The trajectory is calculated using GG_curves_3d(a fantastic piece of code) where you plot in at least 5 x,y,z co-ords and the trajectory is mapped.

So, has anyone a math routine to resolve something like:

1. My man is at x,y,and z of 3,3,0 and is looking due east.
2. Start position of bomb will be 3,3,1 and end position 8,3,1 (thrown within an arc)
3. Man turns north, still at x,y and z of 3,3,0 throws bomb but this time the destination of bomb's arc will be 3,8,1.

If anyone can shed some light on the syntax to resolve what way I'm facing, and subsequently extrapolate a destination co-ord for the bomb ? I've a sneaking suspicion I might need to use polar co-ords or j-notaion however it's been about 18 years or so since I last used that math. I store the data regarding the 5 x,y and z co-ord within an array, for population.

My next step will be to add a 'force' factor to the melt which will factor up the arc and the distance the hand thrown bomb goes. B3D Rocks (;-)

Thanks in advance, Blitzplotter.


syntax(Posted 2007) [#2]
ok i have a much simpler solution should you choose to try it. basicly get a physics engine (i use devil physics engine, but thats just me) and make an object that has physics and make it go in the direction that you are facing at the ark you wish. while the game is updating keep a timer for each bomb and when the timer for each bomb reaches a certain number, delete the object and its physics and use whatever explosion effect you want.

basicly: let the physics engine do the work for you


Blitzplotter(Posted 2007) [#3]
thanks syntax, this may end up being my solution. I am having limited succes with moving an entity (a bullet) move exceptionally fast to where I want the grenade to end up, extrapolating the co-ord then calculating the arc from player(current x,y,z) and bullet/grenade x,y,z.


Hujiklo(Posted 2007) [#4]
Are you translating or moving the entity? If you can't be bothered to translate it and code for directions then simply use moveentity - point it in the direction of the target first then adjust its pitch according to the arc you've apparently already calculated. I fudged my own arced trajectories this way.


Blitzplotter(Posted 2007) [#5]
I'm moving the bullet entity, I made the error of using a 3rd attempt at a bullet, when I should have just used the existing bullet with a different move distance. Haven't 'translated' an entity and I'm not sure what that means.

Cheers Hukjiko.


syntax(Posted 2007) [#6]
moving an entity in blitz will cause blitz to look at the rotation of the object and move it according to IT'S x,y, or z axis.

i like to think of it as: there is the world's coordinate plane, and then each entity has its own coordinate planes.

Translating an entity will move the entity across the world's coordinate plane and moving will move the entity across the entity's coordinate plane.


anywho.... so are you just trying to get a bullet to go in a certain place and you want to make SURE that it goes there or what?


Doggie(Posted 2007) [#7]
Function tossgrenade()
If grnde>0 Then grnde=grnde-1
If grnde<1 Then Return
grnz=grnz+1
b.grenade = New grenade
b\entity = CreateSprite()

PositionEntity b\entity, EntityX(player), EntityY(player)+2, EntityZ(player)
ScaleSprite b\entity, .4,.4
EntityColor b\entity,50,85,50


gvel=8
End Function
Function updategrenade()
For b.grenade = Each grenade
RotateEntity b\entity, EntityPitch(player), EntityYaw(player), EntityRoll(player)
gvel=gvel-1
MoveEntity b\entity, 0,gvel,15

gx#=EntityX(b\entity)
gy#=EntityY(b\entity)
gz#=EntityZ(b\entity)
g_y#=TerrainY(terrain1,gx#,gy#,gz#)
If gy#<g_y#
fill in the blank from here
This code will toss a grenade in the direction "player" is facing.


Rob Farley(Posted 2007) [#8]
This might help you with general lobbing of things in a direction.

http://www.blitzbasic.com/Community/posts.php?topic=72799


Gillissie(Posted 2007) [#9]
Blitzplotter, thanks for the compliment on the GG_Curves_3D code. However, I agree that it's not the best solution for what you're doing here.

I don't agree that implementing a physics engine is the easiest, or even necessary to do a simple lob.

What I've done before with arcing arrows is to create a pivot, parent your grenade to the pivot (so the pivot is the grenade's parent). Rotate the pivot in the direction of the trajectory (away an upward from the character), then use MoveEntity in the z direction on the pivot. Also, gradually use TurnEntity to rotate the pitch downward as it flies. It will make a very smooth arch in the direction it's heading. By using a pivot to do the movement, you are free to rotate the grenade independently as it flies without affecting the trajectory.


Blitzplotter(Posted 2007) [#10]
@syntax, em, I am trying to determine x,y, and z cords for a grenade lets say distance {x} from the player.

@Doggie thanks for the code.

@Rob, will check this out tomorrow

@Gillissie, thanks for the advice, I wasn't to keen on going down the physics engine road for 'lobbing' something in an arc.

Thanks all for the advice, I will post my results in a .avi when I get it working. Gotta go do stuff.....


syntax(Posted 2007) [#11]
well not that you have to use my advise or anything(and really im not insulted or trying to prove a "grand point")but one more thing i guess i should note is that if you do go down the physics engine road, you also wont have to program the grenades bouncing off a wall or other geometry as the physics engine will do this for you.

just something else to consider in deciding what road to travel.


Blitzplotter(Posted 2007) [#12]
thanks syntax, I'm at the very early stages of 3D motion development, and I freely admit I'm initially going for a dumb ish grenade. Who knows whether I'll get as far as physics engines, I've a number of other projects on the go, BMax, C, C++, assembly to name a few. I do think physics engines seem appealing - but also enjoy the challenge of messing about trying to achieve some goals without choosing the easier road before I've got an appreciation of stuff.

regards, blitzplotter.


Blitzplotter(Posted 2007) [#13]
My grenades now kill my enenmies.... yeee hah!!! Oh, and you can elect to drive a car in remote mode, mowing down enemies should there be too many of them. You can call the car back should you drive it to far away.

Many thanks to everyone who helped out.