• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Find location and move unit there

Status
Not open for further replies.
Level 12
Joined
Apr 16, 2010
Messages
584
Hello! Guys/girls, i got problems with my trigger, i want to move unit to some location offset by (let's say 10) and towards (let's say 240 degrees), but i also want to play that unit animation during its moving. I'm new to JASS to i don't really know hot to do that, i searched a lot of forums but still...
Okay so i did this
  • Custom script: call SetUnitX( udg_Caster , GetUnitX(udg_Caster) )
  • Custom script: call SetUnitY( udg_Caster , GetUnitY(udg_Caster) )
But as i know (hopefully) it should look something like that:
  • Custom script: SetUnitX(udg_Caster),GetUnitX(udg_Caster)+udg_Range*Cos(udg_Angle)
  • Custom script: SetUnitY(udg_Caster),GetUnitY(udg_Caster)+udg_Range*Sin(udg_Angle)
I get syntax error in here ^^ Any help?

But i need to know where and how to add distance and angle (if i did it wrong)? and why do i need to make angle in radians only?
Also i need a third script that finally move Caster to the point.
Hope i told everything clear and you'll easily understand!
Help is really appreciated!
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
What baassee said.

In GUI (bj functions), angles are in degrees, in JASS (non-bj functions) angles are in radians.

SetUnitX(udg_Caster[udg_Index3]),GetUnitX(udg_Caster[udg_Index3])+udg_Speed[udg_Index3]*Cos(udg_Angle[udg_Index] * bj_DEGTORAD)

->
SetUnitX(udg_Caster[udg_Index3],GetUnitX(udg_Caster[udg_Index3])+udg_Speed[udg_Index3]*Cos(udg_Angle[udg_Index] * bj_DEGTORAD))

Remove the first ")" and add one ")" at the very end.
 
Level 12
Joined
Apr 16, 2010
Messages
584
Strange...
Could you guys test
SetUnitX(udg_Caster[udg_Index3],GetUnitX(udg_Caster[udg_Index3])+udg_Speed[udg_Index3]*Cos(udg_Angle[udg_Index] * bj_DEGTORAD))
line in your WE or some program.
Coz if you say that this is right then it must work.
Edit: okay it's getting late and i need to learn a bit, so see you tomorrow.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
Every opeing brackets "(" needs a closing brackets ")"

Functions take all thair arguments as a list within brackets.

call DSG(1,2,3)

Brackets can also be used like in mathematics to change the order code gets executed.
call DSG(1,2,(4+5)/3)

You can do completly retarded brackets as well
call DSG(((1)),(2),((4+5)/3))
as long as they all match up.

You also often need to pass a function as an argument to another function which again takes a list of arguments between brackets.
call DSG(pro(1),good(2),error(doublenested(8,6)))
As long as the functions with the approtiate arguments exist, the above is valid as well.
 
Well here's a examble of how you could do it.
JASS:
local real X = GetUnitX( udg_Caster[ udg_Index3 ] )
local real Y = GetUnitY( udg_Caster[ udg_Index3 ] )
call SetUnitX( udg_Caster[ udg_Index3 ], X + udg_Speed[ udg_Index3 ] * Cos( udg_Angle[ udg_Index ] * bj_DEGTORAD ) )
call SetUnitY( udg_Caster[ udg_Index3 ], Y + udg_Speed[ udg_Index3 ] * Sin( udg_Angle[ udg_Index ] * bj_DEGTORAD ) )

NOTE: Locals are always effective, and easily implemented to GUI / Jass.
Just remember that they need to be in the very beginning of the trigger, otherwise you'll get a error.

Also~ Always remember to make clear triggers, simple examble here...
JASS:
// ##### ##### #####
// TEMPLATE A
//   Use this Template instead of Template B.
//
local real oPosX = GetUnitX( udg_oUnit[ udg_oIndex ] )      // Return unit's X position..
local real oPosY = GetUnitY( udg_oUnit[ udg_oIndex ] )      // ..and Y position.
local real oPosA = GetUnitFacing( udg_oUnit[ udg_oIndex ] ) // Examble Angle, the unit's angle.
local real oMovS = 15                                       // The speed, you can use udg_* also in it.

call SetUnitX( udg_oUnit[ udg_oIndex ], oPosX + oMovS * Cos( oPosA * bj_DEGTORAD ) )
call SetUnitY( udg_oUnit[ udg_oIndex ], oPosY + oMovS * Sin( oPosA * bj_DEGTORAD ) )

// ##### ##### #####
// TEMPLATE B
//   Use Template A instead of this.
//
call SetUnitX( udg_oUnit[ udg_oIndex ], GetUnitX( udg_oUnit[ udg_oIndex ] ) + udg_oSpeed[ udg_oIndex ] * Cos( udg_oAngle[ udg_oIndex ] * bj_DEGTORAD ) )
call SetUnitY( udg_oUnit[ udg_oIndex ], GetUnitY( udg_oUnit[ udg_oIndex ] ) + udg_oSpeed[ udg_oIndex ] * Sin( udg_oAngle[ udg_oIndex ] * bj_DEGTORAD ) )
 
Last edited:
Status
Not open for further replies.
Top