grenades

Blitz3D Forums/Blitz3D Beginners Area/grenades

RogueM(Posted 2008) [#1]
I have a game in which I need grenades. I can get one grenade to work(i.e. it flies in an arch and explodes on impact w/ another object.), but I need multiple grenades. I don't want to do the code over and over to accomodate each grenade, but I don't know how to use a type, array, etc. to do it. Any help?


Mustang(Posted 2008) [#2]
http://www.blitzbasic.com/b3ddocs/command.php?name=Function&ref=2d_cat


Rob Farley(Posted 2008) [#3]
This might help

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


RogueM(Posted 2008) [#4]
how does the c\phys pivot create movement?


Rob Farley(Posted 2008) [#5]
TranslateEntity c\Mesh,EntityX(c\phys),EntityY(c\phys),EntityZ(c\phys)

It's the same as having xspeed, yspeed and zspeed, except all rolled into one variable, with the additional advantage of being able to rotate it and move it in a given direction without having to worry about sine/cosine maths.


RogueM(Posted 2008) [#6]
ok, I see. now that the throwing-multiple-grenades function is good, how can I set up an explosion for each grenade?


Rob Farley(Posted 2008) [#7]
Same principle.

Create a type for your explosion.
Create a function to create an instance (like the newcube() function)
and finally
Create a function to update all explosions (like the updatecubes() function)

Your NewExplosion function would probably accept either x,y,z co-ords and a size

ie
Function NewExplosion(x#,y#,z#,size)
	e.explosion = New explosion
	blah
	blah
	blah
End Function

Function UpdateExplosions()
	For e.explosion = Each explosion
		blah
		blah
	Next
End Function



RogueM(Posted 2008) [#8]
two problems so far (w/ out the xplode). I can't move the point the grenades are thrown from or set a limit on the amount of grenades you can throw, they just keep on coming. once these are fixed there wont be a problem w/ the explosions.


chwaga(Posted 2008) [#9]
i don't understand your problem, code please :)


Rob Farley(Posted 2008) [#10]
Because I'm a caring sharing loving kinda guy...




RogueM(Posted 2008) [#11]
Not to sound idiotic, but, rob farley, how did you do that. I modified the code so that the launcher can move, and if still fires properly from the launcher. ( I don't have time to sift thru code:) ) I got a way to have a grenade-limit, so I'm good there


Rob Farley(Posted 2008) [#12]
You don't have time to sift through the code eh... Sounds more like you can't be arsed. Without sifting through the code you won't learn... however...

There is a pivot (called muzzle) parented to the end of the barrel. The handle of the muzzle entity is passed to the NewGrenade function as 'Launcher' which exposes it's properties within the function.

The start position of the grenade is then placed at the xyz of the that, likewise the trajectory of the grenade is picked up from the yaw, pitch and roll of the same passed entity.

Likewise when the NewExplode is called the handle of the grenade mesh (c\mesh) is passed to it so the explosion happens at the point where the grenade is. Then the explosion itself is handled by exactly the same code which handles the updating of the grenades. The explosion is essentially just a bunch of grenades.

Damn I'm being helpful today... I need to stop this before I make a habit of it.


RogueM(Posted 2008) [#13]
I might point out that I didn't have time to sift thru code at the time I posted. anyway, the world needs more helpful people, there's such a lack of them. sorry for using so much of your time. :)


Doggie(Posted 2008) [#14]
;)@Rob