• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Ball Bouncing off a Wall

Status
Not open for further replies.
Level 5
Joined
Nov 30, 2012
Messages
200
1) How do I make the ball face a certain direction instantly without moving in a semicircle in order to face that direction? I tried setting the turn rate to 9999 and made the movement speed 0, but to no avail.

2) I want the ball to bounce off the wall at the same angle at which it came in. How do you do this? The walls are placed sometimes in a circle around a point or in straight lines.

Thanks.
 
Level 7
Joined
May 11, 2010
Messages
278
1)
  • Actions
    • Unit - Make (Unit) face (Center of (Playable map area)) over 0.00 seconds
    • Unit - Make (Unit) face Degrees over 0.00 seconds
    • Unit - Make (Unit) face (Unit) over 0.00 seconds
There are a few options.
 
Level 5
Joined
Nov 30, 2012
Messages
200
1)
  • Actions
    • Unit - Make (Unit) face (Center of (Playable map area)) over 0.00 seconds
    • Unit - Make (Unit) face Degrees over 0.00 seconds
    • Unit - Make (Unit) face (Unit) over 0.00 seconds
There are a few options.


The unit still curves to turn :\
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
I believe you can't make a unit change their facing instantly. There was some minimum to this (I think it was about 0.7 seconds, but this may be incorrect).
Because of this, you absolutely need a variable for the angle, you cannot use the unit's facing.

To make it bounce, this is a fairly simple pseudocode:
Code:
set angle = 360º - angle
set new loc = loc with offset

if not IsPathable(new loc) then
    set angle = angle + 180º
    set angle = angle % 360º
    set new loc = loc with offset

    if not IsPathable(new loc) then
        set angle = 360º - angle
        set new loc = loc with offset
    endif
endif
With "angle % 360" being the modulo-operator (it also exists in GUI).
psuU04h.jpg
 
Level 5
Joined
Nov 30, 2012
Messages
200
Hmm... so why doesn't this work? (The unit never changes directions).

  • Speed
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Set ballgroup = (Units of type Ball)
      • Unit Group - Pick every unit in bulletgroup and do (Actions)
        • Loop - Actions
          • Set unit = (Picked unit)
          • Set angle = (Facing of unit)
          • Set loc1 = (Position of unit)
          • Set loc2 = (loc1 offset by 10.00 towards angle degrees)
          • Unit - Move unit instantly to loc2
          • Set towergroup = (Units within 88.00 of loc2 matching ((Unit-type of (Matching unit)) Equal to Scout Tower))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in towergroup) Greater than 0
            • Then - Actions
              • Set angle = (360.00 - angle)
              • Set loc1 = (Position of unit)
              • Set loc2 = (loc1 offset by 10.00 towards angle degrees)
              • Set towergroup = (Units within 88.00 of loc2 matching ((Unit-type of (Matching unit)) Equal to Scout Tower))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in towergroup) Greater than 0
                • Then - Actions
                  • Set angle = (180.00 + angle)
                  • Set angle = (angle mod 360.00)
                  • Set loc1 = (Position of unit)
                  • Set loc2 = (loc1 offset by 10.00 towards angle degrees)
                  • Set towergroup = (Units within 88.00 of loc2 matching ((Unit-type of (Matching unit)) Equal to Scout Tower))
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Number of units in towergroup) Greater than 0
                    • Then - Actions
                      • Set angle = (360.00 - angle)
                      • Set loc1 = (Position of unit)
                      • Set loc2 = (loc1 offset by 10.00 towards angle degrees)
                      • Unit - Move unit instantly to loc2
                    • Else - Actions
                • Else - Actions
                  • Unit - Move unit instantly to loc2
            • Else - Actions
              • Unit - Move unit instantly to loc2
      • Custom script: call DestroyGroup( udg_towergroup )
      • Custom script: call DestroyGroup( udg_ballgroup )
      • Custom script: call RemoveLocation( udg_loc2 )
      • Custom script: call RemoveLocation( udg_loc1 )
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Please note that setting all those variables again will leak.
So worst-case scenario, you've got 8 leaks every time the trigger runs.

To get the terrain pathability, I use this function (don't worry about it being JASS, it's just to make it easier):
JASS:
function IsPathable takes real x, real y returns boolean
    call SetItemPosition(udg_Item, x, y)
    
    if GetItemX(udg_Item) == x and GetItemY(udg_Item) == y then
        return true
    endif
    return false
endfunction
It returns true if you can move there, and false if you cannot.
There won't be any need for a unit group if you use this.

Test-map attached.
 

Attachments

  • BounceMove.w3x
    11.6 KB · Views: 149
Level 5
Joined
Nov 30, 2012
Messages
200
Wow, that works perfectly! This would be a good resource for anyone who needs a system like this!
 
Status
Not open for further replies.
Top