point of impact

BlitzMax Forums/BlitzMax Programming/point of impact

Cruis.In(Posted 2006) [#1]
ok so I was trying to add a small explosion animation to the point of impact on a players ship.

problem was finding out how to determine the point of impact on the player ship. guess i have to do a type to handle the updating of the explosion and stuff


North(Posted 2006) [#2]
I guess using the last known position values of the impacting object won't cut it?


Pantheon(Posted 2006) [#3]
Im not sure of your implementation of your game. Is it 2D or 3D? What method are you using for your collision, boundingVolumes or Full per pixel/polygon collision?


Cruis.In(Posted 2006) [#4]
its 2d. I am using imagescollide.

@North
that value changes as soon as it is fired again.


tonyg(Posted 2006) [#5]
How big are the collision objects? If they're smaller missiles then can't the point of impact be the position of the missile as North suggests?
If they're larger objects (such as asteroids) you'll either have to use polygon collisions (which is quite advanced to find an impact point) or set a number of hotspot testing points around each object. It won't be exact but it should be close enough.
If they collision objects rotate or scale then you'll need to apply the same to the hotspots.
This might help.


Cruis.In(Posted 2006) [#6]
yeah they are missles impacting. the thing is that when a missle impacts, it is then deleted and the x and y are gone, or should i do the explosion at the x and y then delete it :)


tonyg(Posted 2006) [#7]
When the missile impacts, create an explosion object and set it's x/y to the missile x/y. Then you can delete the missile but still have the explosion.


Cruis.In(Posted 2006) [#8]
right true, well i set the explosion to the missle x y and it works. didnt before, maybe because the function wasn't complete. thanks alot guys...sorry for confusion.

Function Explode()	
	MidHandleImage(explosion)	
	
	If hit = True 	
		
		SetAlpha 1.0
		SetRotation 0
		
		DrawImage explosion,missle.x,missle.y,frame			
	
		frame :+ 0.3
		If frame > 6 
			hit = False
			frame = 0
		End If
	End If	
End Function


when the animation reaches the last frame, hit becomes false and it stops the animation and resets frame to 0. so when an explosion happens again it starts from frame 0.

i created a type called txplosion as well which works well, but i went with functions as it was simpler and made more sense to create it with a function if it was possible(which it is) than to use OOP.

but im proud of the texplosion type I did. and i can use it for anything else i want to create, any anim, any explosion thing :)


tonyg(Posted 2006) [#9]
I think you should revisit the texplosion object again. The way you're coding will limit you with missile/explosions.
Your function doesn't pass any missile object so it will use whatever missile.x/y is last set regardless of whether it relates to that explosion. In addition, you can't get rid of missile while it's being used.
I see you've also gone with the 'global to program' option for HIT which is poor design.


Cruis.In(Posted 2006) [#10]
yeah I stated in the other thread, I went back to using texplosion, since it can handle multiple explosions using the same fields of the type.


When the missile impacts, create an explosion object and set it's x/y to the missile x/y. Then you can delete the missile but still have the explosion.


i actually already have the explosion object instanced in the type, i globaled it. and i have it called in the loop. exobject.explodeship()
to do an explosion of a ship when hit = true.

But you are saying that ON impact, of if impact, (on collision :) then create an explosion object, do its animation and then delete itself. better memory management? But is it that abd when I only have two objects for explosion anyway? Guess for simple stuff like this it isn't, but the practice is good to do it that way right.

also I used hit as a global just to finish it and test the animation and stuff make sure it was working before I changed it. :)

there are a couple of booleans which I have declared as global in my globals.bmx to control the life and death of the player, such as playing... dead... etc, is that oK? because i have some functions which need to know the state of those conditions, so they can do what I want them to do, based on whether the player is alive or dead.

I guess I can put HIT in a field in the explosion type, and put if object.hit = true in my function.


Pantheon(Posted 2006) [#11]
Plug and Play baby ;)
This ones for free.



You should use a better blending function than SIN because its a bit wimpy. ALso the timing for the explosion is dictated by the frame rate. This is realy bad and you should integrate it with your game timer. Changing from DrawOval to your frame based animation should be rather breezy. Other than that I hope you can put this code to good use, have fun.


Cruis.In(Posted 2006) [#12]
thanks, thats some nice code!

looks like i could use it for a shield hit effect too. i want my shield invisible around the ship. setalpha 0. but still for the image to be there, so when a missle collides with the shield, it flares for a bit then goes back down to its invisible self.


Cruis.In(Posted 2006) [#13]
as I suspected, setting the point of impact to missle x and y, works for one missile. If you are firing multiple missiles, hitting the target one after the other, you dont see the explosion. my guess is because a new missile x and y has started before the other one has reached the target.... so only the last missiles impact animation will be done.


Pantheon(Posted 2006) [#14]
Are you using global variables to implement your misiles or a type structure? Can you see more than one missile on the screen at a time? You could adapt the explosion code I wrote to handle the creation of missiles with a direction, etc.
If you would like to do that then I could walk you through it.


tonyg(Posted 2006) [#15]
My guess is your code design is wrong. Everything needs to be seperate objects.
This *might* help



Cruis.In(Posted 2006) [#16]
i dont know, it just isn't working, my mind is clay right, probably tired from work. its 3 a.m

I normally leave something and come back to it fresh and solve it. but this is frustrating to leave.

my objects are separate because they move separate update separate and impact separate. when one missile impacts and gets deleted, all the rest are not deleted. each missile impact does its damage, i can multiple missiles all over the screen, so that means each missile object is updated separate. i more feel the problem is with how i can creating the explosion.


North(Posted 2006) [#17]
Give your TMissile the methods 'explode' and 'remove'

explode deals with the animation of the fireball
remove does just that

Maybe you could just post all the relevant pieces of code here, no?


Cruis.In(Posted 2006) [#18]
ok I followed tonyg's code a little more closely, it was as I suspected. The missile code was fine, it was just an explosion for each impact that wasn't being done.

so I added a create function for the explosion, then put the update and draw functions in the main loop. The update does an update for each explosion and the draw, draws each explosion.

the create function is called in my collision code when the missile impacts a target, which starts the ball rolling updating it and drawing it.

I had the drawing stuff basically in the update, and then I called the draw function in the update function, these ways didn't work. I wanted this way though to avoid putting more than neccessary in the loop.

i think i can probably put them all now in one function and call that function in the loop

func goInLoop()
update()
draw()
end func

put goInloop() in the main loop? :)