| 05-23-2009, 09:52 AM | #1 |
Hey all, I have what I believe is a relatively simple question to ask. Basically what I want is that when a unit enters a certain region, he is automatically moved backwards a certain range. Like I said, backwards, meaning that I'd prefer it if the guy was facing upwards when entering the region, he'd also face upwards when going backwards. I'd prefer a vJass answer, thanks in advance. |
| 05-23-2009, 10:42 AM | #2 |
JASS://=========================================================================== //Remove these and replace the call with whatever your one is called if you already have these functions function ProjectX takes real x, real inc, real a returns real return x+inc*Cos(a*bj_DEGTORAD) endfunction function ProjectY takes real y, real inc, real a returns real return y+inc*Sin(a*bj_DEGTORAD) endfunction //=========================================================================== function MoveBackwardsConditions takes nothing returns boolean //idk if you need any checks return true endfunction function MoveBackwardsActions takes nothing returns nothing local unit u=GetEnteringUnit() local real x=GetUnitX(u) //Don't really need this but it makes the SetUnitPosition easier to read local real y=GetUnitY(u) // ^ local real a=GetUnitFacing(u) local real inc=200 //however far you want the unit to move, don't really need a variable for this call SetUnitPosition(u, ProjectX(x, inc, a), ProjectY(y, inc, a) set u=null endfunction //=========================================================================== function InitTrig_MoveBackwards takes nothing returns nothing local region SomeRegion=CreateRegion() local trigger t=CreateTrigger() //setup the region here call TriggerRegisterEnterRegion(t, SomeRegion, Condition(function MoveBackwardsConditions)) call TriggerAddAction(t, function MoveBackwardsActions) set t=null set SomeRegion=null endfunction ? |
| 05-23-2009, 11:03 AM | #3 |
Didn't work, might've been me who failed or it could've been the code. 1st of all, how do I make it check when the unit enters exactly _my_ region, let's just call that region test, right now it seems that part is missing. 2nd of all, I commented out the TriggerRegister... part and ticked the Run @ Map Init box, yet nothing happened. |
| 05-23-2009, 11:49 AM | #4 | ||
Quote:
JASS:function InitTrig_MoveBackwards takes nothing returns nothing local region SomeRegion=CreateRegion() local trigger t=CreateTrigger() //setup the region here call TriggerRegisterEnterRegion(t, SomeRegion, Condition(function MoveBackwardsConditions)) call TriggerAddAction(t, function MoveBackwardsActions) set t=null set SomeRegion=null endfunction Quote:
|
| 05-23-2009, 12:02 PM | #5 |
The trigger needs to be called MoveBackwards, or it wont do the InitTrig function (I think). |
| 05-23-2009, 12:14 PM | #6 |
So "SomeRegion" should be for example: "gg_rct_test"? EDIT: JASS:function ProjectX takes real x, real inc, real a returns real return x+inc*Cos(a*bj_DEGTORAD) endfunction function ProjectY takes real y, real inc, real a returns real return y+inc*Sin(a*bj_DEGTORAD) endfunction function MoveBackwardsConditions takes nothing returns boolean return true endfunction function MoveBackwardsActions takes nothing returns nothing local unit u=GetEnteringUnit() local real x=GetUnitX(u) local real y=GetUnitY(u) local real a=GetUnitFacing(u) local real inc=200 call SetUnitPosition(u, ProjectX(x, inc, a), ProjectY(y, inc, a)) set u=null endfunction function InitTrig_MoveBackwards takes nothing returns nothing local region gg_rct_test=CreateRegion() local trigger t=CreateTrigger() call TriggerRegisterEnterRegion(t, gg_rct_test, Condition(function MoveBackwardsConditions)) call TriggerAddAction(t, function MoveBackwardsActions) set t=null set gg_rct_test=null endfunction The trigger is idd called MoveBackwards. |
| 05-23-2009, 12:44 PM | #7 |
You haven't set the region up at all. If you are trying to use "Regions" that you create in the main editor window, they are actullay rect's. JASS:function InitTrig_MoveBackwards takes nothing returns nothing local region someRegion=CreateRegion() local trigger t=CreateTrigger() call RegionAddRect(someRegion, gg_rct_test) //This will add the "Region" (actually a rect) you created in the editor to the region call TriggerRegisterEnterRegion(t, someRegion, Condition(function MoveBackwardsConditions)) call TriggerAddAction(t, function MoveBackwardsActions) set t=null set someRegion=null endfunction |
| 05-23-2009, 12:54 PM | #8 |
call RegionAddRect(someRegion, gg_rct_test)
Why rct if we're working with rect? I'm not to familiar with the region prefixes. |
| 05-23-2009, 12:58 PM | #9 | |
Quote:
|
| 05-23-2009, 01:22 PM | #10 |
Try to not use unit facing when projecting at angles. Instead, find the angle between GetRectCenterX() and the unit's x and GetRectCenterY() and the unit's y. Or, since rects are rectangular, and you might want to move back not based on a circular pattern but directly to the left or right, you could move back horizontally or vertically depending on whether the unit's x distance is greater than or less than the width of the rectangle. |
