Wc3C.net Physics regarding units correctly bouncing of walls
 Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar

 12-31-2009, 01:25 PM #1 Na_Dann_Ma_GoGo User   Join Date: Feb 2008 Posts: 125 Physics regarding units correctly bouncing of walls Hi there, I'm really struggling with making units bounce from e.g. walls (in general places with higher terrain height (z)). I know that the angle of incidence equals the angle of reflexion. However I need to "convert" those angles to the ones Wc3 uses (math. unit circle). Or easier, overall, how do I bounce units physically correct in Wc3? How do I detect when they bounce ( periodically z-height detection around the units? (collision?)) and what the angle will be? I'm completely stuck there and think I do something basically wrong. Edit: As an example. A unit flies towards a horizontal wall with an angle of 10° in Wc3. I know it'll bounce of with a 350°. But I've yet to find a formula that works for all angles and all differently angled walls. Last edited by Na_Dann_Ma_GoGo : 12-31-2009 at 01:32 PM.
 12-31-2009, 01:32 PM #2 Tot †6†     Join Date: Oct 2008 Posts: 841 are your walls only higher terrain or also doodads? are you useing blizz movement-system? __________________ Current Projects: Masters Of WarCraft: Some mixture of AoS and RPGTerrain: 100%, Coding: 75%, Heroes: 0%, Items: 0%, Creeps: 0%, Upgrades: 0% hunting emos____________________________________ scheiss kack dreck sausacksau bundeswehr
 12-31-2009, 02:11 PM #3 DioD obey     Join Date: Feb 2006 Posts: 1,532 Submissions (4) check vector system in resource section.
12-31-2009, 02:30 PM   #4
Na_Dann_Ma_GoGo
User

Join Date: Feb 2008
Posts: 125

Quote:
 Originally Posted by Tot are your walls only higher terrain or also doodads? are you useing blizz movement-system?

Currently rather higher terrain as I guess doodads do need extra processing power? Not sure what you mean about blizz moving-system though.

@ DioD gonna do that.

 12-31-2009, 02:43 PM #5 Tot †6†     Join Date: Oct 2008 Posts: 841 blizz moving system: non-triggered moving of things if your using your own movement system: check the terrain level with GetTerrainCliffLevel takes real x, real y returns integer at start and endpoint. If it's different, then calculate the distance between these 2 points and get the point at which the level changes. Now youre calculating the dist to this point from the start and substract it from the overall distance. Now you calculate the impact angle and do JASS:```call SetUnitX(u,BouncePointX+Cos(BounceAngle)*SubstractDistance) call SetUnitY(u,BouncePointY+Sin(BounceAngle)*SubstractDistance) ``` and check again with the bouncePoint as start and the calculated point as end. __________________ Current Projects: Masters Of WarCraft: Some mixture of AoS and RPGTerrain: 100%, Coding: 75%, Heroes: 0%, Items: 0%, Creeps: 0%, Upgrades: 0% hunting emos____________________________________ scheiss kack dreck sausacksau bundeswehr
12-31-2009, 02:57 PM   #6
Na_Dann_Ma_GoGo
User

Join Date: Feb 2008
Posts: 125

Quote:
 Originally Posted by Tot blizz moving system: non-triggered moving of things if your using your own movement system: check the terrain level with GetTerrainCliffLevel takes real x, real y returns integer at start and endpoint. If it's different, then calculate the distance between these 2 points and get the point at which the level changes. Now youre calculating the dist to this point from the start and substract it from the overall distance. Now you calculate the impact angle and do JASS:```call SetUnitX(u,BouncePointX+Cos(BounceAngle)*SubstractDistance) call SetUnitY(u,BouncePointY+Sin(BounceAngle)*SubstractDistance) ``` and check again with the bouncePoint as start and the calculated point as end.

Well I use a triggered movement system of my own.
And I totally get your idea behind this thought I rather use
JASS:
```call MoveLocation(LOC,targ_x,targ_y)
if GetLocationZ(LOC)-.current_z >= 40 then ...```
as I thought the clff level is.. well the cliff level and not the terrain height?

But my real problem is this:
Quote:
 Now you calculate the impact angle
How shall I do it, especially when I don't even know the obstacles normal (if hope that's the real term). And regarding that normal the impact angle changes...

 12-31-2009, 03:16 PM #7 Tot †6†     Join Date: Oct 2008 Posts: 841 the impact angle is always 0°<=impact angle<=90° and he can be calculated via: direction of the wall (either 0° or 90°[180°, 270° and 360° are not needed, cause 180°, 360° is 0° and 270° is 90° (direction of the wall is unimportant)]) - facing of the impacting unit --> JASS:```function GetImpactAngle takes real wallAngle, unit u returns real local real impactAngle=wallAngle-GetUnitFacing(u) if impactAngle<0 then set impactAngle=-impactAngle endif if impactAngle>2*bj_PI then set impactAngle=ModuloReal(impactAngle,2*bj_PI) endif if impactAngle>0.5*bj_PI and impactAngle<=bj_PI then //wc3 is calculating with radiansnot with degrees set impactAngle=impactAngle-0.5*bj_PI elseif impactAngle>bj_PI and impactAngle<=1.5*bj_PI then set impactAngle=impactAngle-bj_PI elseif impactAngle>1.5*bj_PI and impactAngle<=2*bj_PI then set impactAngle=impactAngle-1.5*bj_PI endif ``` to get the walls angle, check one point on the left and one on the right side of your impact point and compare the height, if it's equal the angle is 0°, otherwise it's 90° __________________ Current Projects: Masters Of WarCraft: Some mixture of AoS and RPGTerrain: 100%, Coding: 75%, Heroes: 0%, Items: 0%, Creeps: 0%, Upgrades: 0% hunting emos____________________________________ scheiss kack dreck sausacksau bundeswehr
 12-31-2009, 03:36 PM #8 Na_Dann_Ma_GoGo User   Join Date: Feb 2008 Posts: 125 I kinda got to this point more or less already, what I'm really searching for a is a formula to use instead of the "if, elseif, ..." stuff. That also should work for walls of all angles and not just straight horizontal / vertical ones. Edit: Also I still don't know how get from the impactAngle to the new bounceAngle (new Unit movement/facing direction), as that one ranges from 0 to 2 PI. Last edited by Na_Dann_Ma_GoGo : 12-31-2009 at 04:15 PM.
 01-01-2010, 02:06 AM #9 Switch33 User   Join Date: Oct 2003 Posts: 150 http://www.thehelper.net/forums/showthread.php?t=124461
 01-01-2010, 01:45 PM #10 Na_Dann_Ma_GoGo User   Join Date: Feb 2008 Posts: 125 Ah thanks that's really helpful!
01-01-2010, 09:47 PM   #11
Anitarf
Procrastination Incarnate

Development Director

Join Date: Feb 2004
Posts: 8,189

Submissions (19)

I find doing this with angles rather cumbersome and only worth it if your "physics" are meant to be oversimplified (for example, if the walls are allowed to only face four directions) for gameplay reasons. Otherwise, I find a general vector solution much more practical.
__________________
 Cinema Workshop released! Let's make some cinematics! Editor's version of the winner of the Blizzard's Cinematic Contest: The Spirit of Vengeance

 01-01-2010, 10:27 PM #12 Na_Dann_Ma_GoGo User   Join Date: Feb 2008 Posts: 125 Hmm yah. For now I got the oversimpliefied version ;) I may switch to vectors. But that depends. Working with vectors doesn't really change THAT much or? I guess I just need to do all the SetUnitX() SetUnitY() stuff with the x/y vector parts and the fly height with the z part. And on collision and so I do add / subtract and all that stuff? I did have vectors half a year ago at school but I dunno how working with them in Wc3 ist^^
01-02-2010, 09:04 PM   #13
Anitarf
Procrastination Incarnate

Development Director

Join Date: Feb 2004
Posts: 8,189

Submissions (19)

Well, it depends on how exactly you want your physics to function, but a simple bouncing sample is included in the vector system test map.
__________________
 Cinema Workshop released! Let's make some cinematics! Editor's version of the winner of the Blizzard's Cinematic Contest: The Spirit of Vengeance

 01-03-2010, 11:17 AM #14 Na_Dann_Ma_GoGo User   Join Date: Feb 2008 Posts: 125 Hmm that's indeed pretty cool. I really consider switching to this however... how would you deal with bouncing off from doodads? I guess there's nothing like this implanted. But in my maps walls may be made of doodads and not terrain all the time. And you cannot manipulate the terrain in a way that it fits the doodads size etc. and is even hidden by the doodad.
 01-03-2010, 01:07 PM #15 Viikuna- User     Join Date: Feb 2009 Posts: 203 Use destructibles instead of doodads and attach all the needed data to them with some hashtables, so when you pick a destructible which is in way of your projectile, you can get its height and length and other thingies like that are needed to calculate a nice and smooth collinsion. You can make destructibles untargettable, so they look exactly like doodads, this is no problem. __________________ No Marlo, no game.