bouncing system code

I am looking for simple GUI or custom script system to when hook hits a wall it will bounce depending on from which site the hook encountered.

I was using this system: But the hook doesn t bounce correctly.

  • Set VariableSet Point = (Position of HookMain[(Integer A)])
  • Set VariableSet Point2 = (Position of (Picked destructible))
  • Set VariableSet Real = ((Angle from Point to Point2) - 180.00)
  • Custom script: call RemoveLocation(udg_Point)
  • Custom script: call RemoveLocation(udg_Point2)
  • Unit - Make HookMain[(Integer A)] face Real
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
You're on the latest patch or at least 1.31 so you can rely on Special Effects now which have Yaw, Pitch, Roll and less overhead than units. They're almost objectively better than using Dummy units in all cases.
  • Special Effect - Set Yaw of HookMainSfx[X] to (Degrees(Real))
There's also a new action to make a unit face an angle immediately:
  • Unit - Make HooMain[X] face Real immediately
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
I mean I am looking for function (math) to replace this:
  • Set VariableSet Real = ((Angle from Point to Point2) - 180.00)
Because this function doesnt bounce the hook correctly.
I am on latest patch.
You could ask ChatGPT for help, I'm terrible with math.

Warcraft 3 is also limited in what it can do but I've definitely seen people achieve this. Pathing is made up of rectangles so it's not like you can easily detect the exact "collision point" like you would in a game engine that has mesh colliders that wrap around the terrain/models.

Here's the pseudo-code it spit out for me:
vJASS:
function OnHookCollision takes nothing returns nothing
    local location HookPos = GetUnitLoc(Hook)
    local location TargetPos = GetUnitLoc(HookTarget)
    local location CollisionPoint = GetUnitLoc(Collision)
    local vector IncidentVector
    local vector SurfaceNormal = GetSurfaceNormal(CollisionPoint)
    local real DotProduct
    local vector ReflectionVector
    local location NewTargetPos
    local real HookLength
 
    // Step 1: Calculate the Incident Vector
    set IncidentVector = Normalize(LocationSubtract(TargetPos, HookPos))
 
    // Step 2: Calculate the Dot Product
    set DotProduct = DotProduct(IncidentVector, SurfaceNormal)
 
    // Step 3: Calculate the Reflection Vector
    set ReflectionVector = VectorSubtract(IncidentVector, VectorScale(SurfaceNormal, 2 * DotProduct))
 
    // Step 4: Set the New Target Position
    set HookLength = DistanceBetweenPoints(HookPos, TargetPos)
    set NewTargetPos = LocationAdd(CollisionPoint, VectorScale(ReflectionVector, HookLength))
 
    // Update the Hook's target position
    SetUnitPositionLoc(Hook, NewTargetPos)
 
    // Cleanup
    call RemoveLocation(HookPos)
    call RemoveLocation(TargetPos)
    call RemoveLocation(CollisionPoint)
    call RemoveLocation(NewTargetPos)
endfunction
Obviously it doesn't understand Jass perfectly as vectors don't exist and most of those functions don't exist. Plus the TargetPos doesn't involve a Unit and the CollisionPoint would probably be the same as the TargetPos. But I imagine you could work with it to figure out some math that would work. A vector is just a Location -> a container of x, y, and z coordinates.
 
Top