| 08-26-2007, 12:57 PM | #1 |
Hello, I'm trying to detect if a collision missile hit the cliff, because I want it to bounce from it. This is very complicated, I know. The bounce angle, cliff detection and everything. I'm open to complicated solutions because I don't think a simple one exists. Thanks in advance. |
| 08-26-2007, 02:04 PM | #2 |
terrain normal function from any vector system |
| 08-26-2007, 02:36 PM | #3 |
Terrain normal vector can be obtained from the cross product of two vectors placed on the terrain at the point of interest. Something like this: Cross Product:static method CrossProduct takes vector v1, vector v2 returns vector local real x = (v1.y*v2.z-v1.z*v2.y) local real y = (v1.z*v2.x-v1.x*v2.z) local real z = (v1.x*v2.y-v1.y*v2.x) return vector.create(x, y, z) endmethod Terrain Normal:static method GetTerrainNormal takes real x, real y, real radius returns vector local vector x_vec local vector y_vec local vector normal local real z call MoveLocation(TempLoc, x - radius, y) set z = GetLocationZ(TempLoc) call MoveLocation(TempLoc, x + radius, y) set x_vec = vector.create(2 * radius, 0.0, GetLocationZ(TempLoc) - z) call MoveLocation(TempLoc, x, y - radius) set z = GetLocationZ(TempLoc) call MoveLocation(TempLoc, x, y + radius) set y_vec = vector.create(0.0, 2 * radius, GetLocationZ(TempLoc) - z) set result = vector.CrossProduct(x_vec, y_vec) call x_vec.destroy() call y_vec.destroy() return normal endmethod (I am assuming you know vJass well enough to be able to fill in the gaps - like making a vector struct etc.) Cliffs have a 45 degree angle, but visually appear to have a 90 degree angle. You will need to find some way of detecting if the angle is 45 degrees and the terrain is non-pathable etc. then remove the z-component from the terrain normal vector. To bounce you could do something like rotating the vector of the missile around the terrain normal, and then amplifying it by -1. I am not sure if the above are the best methods/work... the best way to go is probably to look through some vector systems, to see how these problems were solved. |
