| 12-31-2009, 12:25 PM | #1 |
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. |
| 12-31-2009, 12:32 PM | #2 |
are your walls only higher terrain or also doodads? are you useing blizz movement-system? |
| 12-31-2009, 01:11 PM | #3 |
check vector system in resource section. |
| 12-31-2009, 01:30 PM | #4 | |
Quote:
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, 01:43 PM | #5 |
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. |
| 12-31-2009, 01:57 PM | #6 | ||
Quote:
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 ... But my real problem is this: Quote:
|
| 12-31-2009, 02:16 PM | #7 |
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° |
| 12-31-2009, 02:36 PM | #8 |
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. |
| 01-01-2010, 01:06 AM | #9 |
| 01-01-2010, 12:45 PM | #10 |
Ah thanks that's really helpful! |
| 01-01-2010, 08:47 PM | #11 |
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. |
| 01-01-2010, 09:27 PM | #12 |
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, 08:04 PM | #13 |
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. |
| 01-03-2010, 10:17 AM | #14 |
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, 12:07 PM | #15 |
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. |
