I want to make a delay on rotating, like in mope.io, but i don’t know how, pleas help me
2 Likes
Disable the “Rotate to face mouse cursor” setting on the unit, and make a script that rotates every unit a fraction of the way to their target rotation every frame, so there is a delay for the unit’s rotation to reach the target rotation:
Script in text form
Triggers: every frame (roughly every 50ms)
actions:
for all units in ( all units in the game )
do:
if (( unit type of ( selected unit ) )) == (Unit)
then do:
set variable currentAngle as ( facing angle of ( selected unit ) in radians )
set variable targetAngle as ( angle between positions ( position of ( selected unit ) ) and ( get ( owner of ( selected unit ) ) 's mouse cursor position ) )
set variable angleDifference as ((targetAngle) - (currentAngle))
if (angleDifference) < (-3.14159)
then do:
increase angleDifference by 6.28318
else do:
if (angleDifference) > (3.14159)
then do:
decrease angleDifference by 6.28318
else do:
rotate ( selected unit ) to ((currentAngle) + (((angleDifference) / (4)))) radians
else do:
Raw JSON:
{
"triggers": [
{
"type": "frameTick"
}
],
"conditions": [
{
"operator": "==",
"operandType": "boolean"
},
true,
true
],
"actions": [
{
"type": "forAllUnits",
"unitGroup": {
"function": "allUnits"
},
"actions": [
{
"type": "condition",
"conditions": [
{
"operandType": "unitType",
"operator": "=="
},
{
"function": "getUnitTypeOfUnit",
"entity": {
"function": "selectedUnit"
}
},
"fighter"
],
"then": [
{
"type": "setVariable",
"value": {
"function": "unitsFacingAngle",
"unit": {
"function": "selectedUnit"
}
},
"variableName": "currentAngle",
"comment": "global variables used for convenience and readability"
},
{
"type": "setVariable",
"value": {
"function": "angleBetweenPositions",
"positionA": {
"function": "getEntityPosition",
"entity": {
"function": "selectedUnit"
}
},
"positionB": {
"function": "getMouseCursorPosition",
"player": {
"function": "getOwner",
"entity": {
"function": "selectedUnit"
}
}
}
},
"variableName": "targetAngle"
},
{
"type": "setVariable",
"value": {
"function": "calculate",
"items": [
{
"operator": "-"
},
{
"function": "getVariable",
"variableName": "targetAngle"
},
{
"function": "getVariable",
"variableName": "currentAngle"
}
]
},
"variableName": "angleDifference"
},
{
"type": "condition",
"conditions": [
{
"operator": "<",
"operandType": "number"
},
{
"function": "getVariable",
"variableName": "angleDifference"
},
-3.14159
],
"then": [
{
"type": "increaseVariableByNumber",
"variable": "angleDifference",
"number": 6.28318
}
],
"else": [],
"comment": "turning clockwise is shorter than turning >180 degrees counterclockwise"
},
{
"type": "condition",
"conditions": [
{
"operator": ">",
"operandType": "number"
},
{
"function": "getVariable",
"variableName": "angleDifference"
},
3.14159
],
"then": [
{
"type": "decreaseVariableByNumber",
"variable": "angleDifference",
"number": 6.28318
}
],
"else": [],
"comment": "turning counterclockwise is shorter than turning >180 degrees clockwise"
},
{
"type": "rotateEntityToRadiansLT",
"entity": {
"function": "selectedUnit"
},
"radians": {
"function": "calculate",
"items": [
{
"operator": "+"
},
{
"function": "getVariable",
"variableName": "currentAngle"
},
{
"function": "calculate",
"items": [
{
"operator": "/"
},
{
"function": "getVariable",
"variableName": "angleDifference"
},
4
]
}
]
}
}
],
"else": []
}
]
}
],
"name": "delayed rotation"
}
5 Likes
Can I use unit variables? I’m noticing that we use global variables here, does that work for every unit too?
1 Like
Nevermind, I tested it out, and it works! Thanks so much!
2 Likes