Posted: 30th Aug 2021 3:32
I spent some time researching this and found a rather long and confusing blog about linear algebra and such and I came up with this

+ Code Snippet
Function Atom_GetKineticEnergy(sprite1, sprite2)

	Kinetic as float 
	
	if GetSpriteExists(sprite1) and GetSpriteExists(sprite2)
		
		vx1#=GetSpritePhysicsVelocityX(sprite1)
		vy1#=GetSpritePhysicsVelocityY(sprite1)
		mass1#=GetSpritePhysicsMass(sprite1)
		
		vx2#=GetSpritePhysicsVelocityX(sprite2)
		vy2#=GetSpritePhysicsVelocityY(sprite2)
		mass2#=GetSpritePhysicsMass(sprite2)
		
		Kinetic = Round(0.5 * Pow( (Sqrt(vy1# + vx1#) * mass1#) + (Sqrt(vy2# + vx2#) * mass2#), 2))
	endif
	
EndFunction Kinetic



For the most part it works but I get a small inconsistency when 2 sprites are at a certain angle to each other (around 30 degrees) so it must be my code, pretty sure I am not handling the velocity's right inside the Sqrt(), should those be squared?
Posted: 30th Aug 2021 5:05
i can't help much here but from THIS "collision in 1 dimension", i don't see usage of SQRT but do see:
(0.5*M1*V1)^2 + (0.5*M2*V2)^2 = Joules (how to convert to AppGameKit from there, i dunno - update, i get it now (somewhat) = N m).

what exactly is "wrong" or inconsistent? is it apparent in your last project update?

also, be careful with the built-in Round function. dunno if it's related to the undesired results but take note.
Posted: 30th Aug 2021 5:44
Yes, 16 seconds in I try to merge 2 sprites and they bounce off each other, my kinetic threshold is set to 1000, in other instances when merging at the same distance its fine just the odd occasion the impact threshold is not met (at that range it should or is usually around 1800)

maybe I need to increase my acceleration multiplier at close distances, Ill do a proper log and debug tomorrow and see if I can pin it down, at the forces involved I doubt the rounding error makes a difference to be honest, mass is high and speeds are fast a floating point error would not even register
Posted: 30th Aug 2021 5:50
a) I wouldn't round it
b) How do you apply the result?
Posted: 30th Aug 2021 7:33
The result is simply checked in a if statement (if force>1000) then allow the merge action to take place, else low speed collisions do not merge, I did it this way because allowing all sprites to merge on all collisions was just to erratic and pretty much unplayable the whole thing needed to be slowed down and managed.

how to convert to AppGameKit from there, i dunno


That's pretty much the same calculation I was working from, blackboard algebra, and that function above is the best I can interpret from what I was reading.

I will make it spit the data out to file when I start coding again and examine it that way, there is a lot going on in the moment the left button is lifted and the sprites meet, tweens played, animations set, several states switched etc etc, I think the function ^^ is sound, it never happens with sprites at a distance only those at close proximity so I might be bug checking the wrong function, I calculate the acceleration multiplier based off the distance so the merges look consistent and all contacts should be a relative linear velocity and mass therefore comparable kinetic energy no matter the distance, like I say for the most part I get the expected result, just that oddball random case seen in the video.
Posted: 30th Aug 2021 19:45
Update: I'm an idiot!

Turns out my issue was a dampening, I had to dampen the atoms as they were created (again, was way to erratic) and it was still applied when merging thus reducing the impact force.