Jump to content

Simulating a shockwave with Newton


Volker
 Share

Recommended Posts

I have a ship and an exploding mine.

The mine shall create a shockwave which affects the ship.

Playing with AddBodyForceAtPoint() did not lead me in the right direction.

 

I could do a pointentity() from mine to ship and shoot an invisible body,

but I don't like the idea.

 

Inspirations, please.

Core2DuoE6570 / Windows7 64bit / 4 Gb RAM / Geforce GTX 260 896Mb / LE 2.3

Dell Inspiron 1720 / Vista SP2 / C2D 2.4 / 8600 GM

Link to comment
Share on other sites

You need to do a ForEachEntityInAABBDo on the mine, and run the a function to add massive amounts of force in vectors equivalent to the entity's position minus the mine position.

 

Basically:

 

for each entity in the bounding box (radius or whatever) of the mine

forcevector = entity.position - mineposition

AddBodyForce(entity, forcevector*500) // 500 is your force scalar or whatever

repeat

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

I don't think Newton has repulsive forces. But maybe can be simulated. This is off the top of my head but I would tackle Mk1 like this...

 

Using something like ForEachEntityInAABBDo and give your mine a key that specifies the size of the AABB bounding box (this would be the area of effect).

 

From what I understand, when the mine detonates you want to apply a force to all bodies within that volume around the mine. The amount of force would be distance from the mine entity (with some falloff factor). And supply AddBodyForce with the vector from the ship to the mine (see TFormVector) and your calculated explosive force.

 

 

Other ideas anyone?

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

Thanks, I had forgotten the TFormVector to make sure the forces are local. Falloff as well, as that makes it more realistic.

 

 

I do the same thing with the bullets in the Weaponwerks library.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Could you possibly share how you did it?

 

I would like to add explosives to Weaponwerks as a native projectile type :)

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Hello Tyler,

 

Could you possibly share how you did it?

 

I really wanted to do that, but I thought my solution is

not really good. That's why I wrote "sufficient".

Ok, here it is.

Code in Blitzmax:

 

Function ApplyShockwave(position:tvec3, intensity:Float)
Local body:TBody
For Local gameobject:TGameObject = EachIn TGameObject.list
	body = gameobject.body
	If body <>NULL
		' create a marker to make point of shockwave visible, replace with a pivot later '
		Local marker:TMesh = CreateCylinder(8)	 
		PositionEntity(marker, position)

		Local mpos:TVec3 = EntityPosition(marker)
		Local spos:TVec3 = EntityPosition(body)
		Local distance:Float = EntityDistance(marker, body)

		Local force:TVec3 = New TVec3
		' substract position vecs  and calculate force to apply'
		force.x = (spos.x - mpos.x) / distance
		force.y = (spos.y - mpos.y) / distance
		force.z = (spos.z - mpos.z) / distance

		If distance < 1 Then distance = 1 ' because of massive force if <1 '
		force.x = force.x / distance * intensity
		force.y = force.y / distance * intensity
		force.z = force.z / distance * intensity

		Local tforce:TVec3 = TFormVector(force, marker, Null) ' thanks Flexman! '
		If EntityDistance(TEntity(body), marker) < 10 ' shcokwave only affects bodies in this distance
			AddBodyForce(body, tforce)
		EndIf
	EndIf
Next

I am cycling through all my gameobjects because I couldn't figure out how to pass the two vec3s

to TAABB in Blitzmax at the moment.

Local t:TAABB = New TAABB.Create(Vec2(10, 10), Vec2(0, 0))

throws an error.

Core2DuoE6570 / Windows7 64bit / 4 Gb RAM / Geforce GTX 260 896Mb / LE 2.3

Dell Inspiron 1720 / Vista SP2 / C2D 2.4 / 8600 GM

Link to comment
Share on other sites

It is throwing an error because you are passing two Vec2s, it needs Vec3(X,Y,Z)

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

@Tyler

Yes, of course. Vec3s needed. But it throws the error

already at the create method "Compile Error: Identifier 'Create' not found".

@ VicToMeyeZR

Thats just because the forum uncourteous changed code to comments.

I had to add a ' at the end of every comment and forget that one.

Core2DuoE6570 / Windows7 64bit / 4 Gb RAM / Geforce GTX 260 896Mb / LE 2.3

Dell Inspiron 1720 / Vista SP2 / C2D 2.4 / 8600 GM

Link to comment
Share on other sites

@Tyler

Yes, of course. Vec3s needed. But it throws the error

already at the create method "Compile Error: Identifier 'Create' not found".

@ VicToMeyeZR

Thats just because the forum uncourteous changed code to comments.

I had to add a ' at the end of every comment and forget that one.

 

don't know if i am following this correctly but couldn't you create a mesh at the size you want, then just get the AABB of the mesh using GetEntityAABB?

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

don't know if i am following this correctly but couldn't you create a mesh at the size you want, then just get the AABB of the mesh using GetEntityAABB?

Yes, you are following correctly. Nice workaround.

Will add it to my function.

Core2DuoE6570 / Windows7 64bit / 4 Gb RAM / Geforce GTX 260 896Mb / LE 2.3

Dell Inspiron 1720 / Vista SP2 / C2D 2.4 / 8600 GM

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...