From e4fc9f8710be72c7db0b37eb2b8c462ee0520115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davy=20H=C3=A9lard?= Date: Sun, 12 Mar 2023 02:24:46 +0100 Subject: [PATCH 1/7] [Isometry] Use the top-down animator extension. --- examples/isometric-game/isometric-game.json | 1158 +++++++++++++++++-- 1 file changed, 1031 insertions(+), 127 deletions(-) diff --git a/examples/isometric-game/isometric-game.json b/examples/isometric-game/isometric-game.json index 70d3d1168..3e1fb718e 100644 --- a/examples/isometric-game/isometric-game.json +++ b/examples/isometric-game/isometric-game.json @@ -8354,6 +8354,16 @@ "rotateObject": false, "ignoreDefaultControls": false }, + { + "name": "TopDownMovementAnimator", + "type": "TopDownMovementAnimator::TopDownMovementAnimator", + "TopDownMovement": "TopDownMovement", + "IsScalingAnimation": true, + "AnimationName": "Walk", + "DirectionCount": 8, + "AngleOffset": 45, + "AnimationDirection": 0 + }, { "name": "YSort", "type": "YSort::YSort" @@ -11193,7 +11203,7 @@ ] }, { - "name": "Right", + "name": "Walk0", "useMultipleDirections": false, "directions": [ { @@ -12239,7 +12249,7 @@ ] }, { - "name": "Right_Down", + "name": "Walk1", "useMultipleDirections": false, "directions": [ { @@ -13285,7 +13295,7 @@ ] }, { - "name": "Down", + "name": "Walk2", "useMultipleDirections": false, "directions": [ { @@ -14331,7 +14341,7 @@ ] }, { - "name": "Left_Down", + "name": "Walk3", "useMultipleDirections": false, "directions": [ { @@ -15377,7 +15387,7 @@ ] }, { - "name": "Left", + "name": "Walk4", "useMultipleDirections": false, "directions": [ { @@ -16423,7 +16433,7 @@ ] }, { - "name": "Left_Up", + "name": "Walk5", "useMultipleDirections": false, "directions": [ { @@ -17469,7 +17479,7 @@ ] }, { - "name": "Up", + "name": "Walk6", "useMultipleDirections": false, "directions": [ { @@ -18515,7 +18525,7 @@ ] }, { - "name": "Right_Up", + "name": "Walk7", "useMultipleDirections": false, "directions": [ { @@ -27777,6 +27787,7 @@ "Mindy", "NavMeshPathfindingBehavior", "TopDownMovement", + "TopDownMovementAnimator", "" ] } @@ -28139,6 +28150,12 @@ "name": "TopDownMovement", "type": "TopDownMovementBehavior::TopDownMovementBehavior" }, + { + "name": "TopDownMovementAnimator", + "type": "TopDownMovementAnimator::TopDownMovementAnimator", + "NewAnimationDirection": 0, + "AnimationFrame": 0 + }, { "name": "YSort", "type": "YSort::YSort" @@ -28150,149 +28167,1036 @@ "eventsFunctionsExtensions": [ { "author": "", - "category": "", + "category": "Movement", "extensionNamespace": "", - "fullName": "CharacterMovement", + "fullName": "Top-down movement animator", "helpPath": "", - "iconUrl": "", - "name": "CharacterMovement", - "previewIconUrl": "", - "shortDescription": "", - "version": "", - "description": "Originally automatically extracted from events of the project", - "tags": [], - "authorIds": [], + "iconUrl": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyMy4wLjMsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iSWNvbnMiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgMzIgMzIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDMyIDMyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8Zz4NCgk8cGF0aCBkPSJNNiwyMS4xYy0wLjMsMC0wLjUtMC4xLTAuNy0wLjNsLTQtNC4xYy0wLjQtMC40LTAuNC0xLDAtMS40bDQtNC4xYzAuNC0wLjQsMS0wLjQsMS40LDBzMC40LDEsMCwxLjRMMy40LDE2bDMuMywzLjMNCgkJYzAuNCwwLjQsMC40LDEsMCwxLjRDNi42LDIxLDYuMywyMS4xLDYsMjEuMXoiLz4NCjwvZz4NCjxnPg0KCTxwYXRoIGQ9Ik0yNiwyMS4xYy0wLjMsMC0wLjUtMC4xLTAuNy0wLjNjLTAuNC0wLjQtMC40LTEsMC0xLjRsMy4zLTMuM2wtMy4zLTMuM2MtMC40LTAuNC0wLjQtMSwwLTEuNHMxLTAuNCwxLjQsMGw0LjEsNC4xDQoJCWMwLjIsMC4yLDAuMywwLjQsMC4zLDAuN3MtMC4xLDAuNS0wLjMsMC43bC00LjEsNC4xQzI2LjYsMjEsMjYuMywyMS4xLDI2LDIxLjF6Ii8+DQo8L2c+DQo8Zz4NCgk8cGF0aCBkPSJNMTYsMzEuMUwxNiwzMS4xYy0wLjMsMC0wLjUtMC4xLTAuNy0wLjNsLTQtNC4xYy0wLjQtMC40LTAuNC0xLDAtMS40czEtMC40LDEuNCwwbDMuMywzLjNsMy4zLTMuM2MwLjQtMC40LDEtMC40LDEuNCwwDQoJCXMwLjQsMSwwLDEuNGwtNC4xLDQuMUMxNi42LDMwLjksMTYuMywzMS4xLDE2LDMxLjF6Ii8+DQo8L2c+DQo8Zz4NCgk8cGF0aCBkPSJNMjAuMSw3Yy0wLjMsMC0wLjUtMC4xLTAuNy0wLjNMMTYsMy40bC0zLjMsMy4zYy0wLjQsMC40LTEsMC40LTEuNCwwcy0wLjQtMSwwLTEuNGw0LTQuMWMwLjQtMC40LDEtMC40LDEuNCwwbDQuMSw0LjENCgkJYzAuNCwwLjQsMC40LDEsMCwxLjRDMjAuNiw2LjksMjAuNCw3LDIwLjEsN3oiLz4NCjwvZz4NCjxnPg0KCTxwYXRoIGQ9Ik0xNiwzMGMtMC42LDAtMS0wLjQtMS0xVjNjMC0wLjYsMC40LTEsMS0xczEsMC40LDEsMXYyNkMxNywyOS42LDE2LjYsMzAsMTYsMzB6Ii8+DQo8L2c+DQo8Zz4NCgk8cGF0aCBkPSJNMjksMTdIMmMtMC42LDAtMS0wLjQtMS0xczAuNC0xLDEtMWgyN2MwLjYsMCwxLDAuNCwxLDFTMjkuNiwxNywyOSwxN3oiLz4NCjwvZz4NCjwvc3ZnPg0K", + "name": "TopDownMovementAnimator", + "previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/Glyphster Pack/Master/SVG/Arrows/a6026156355ae5f03613b03971e4ddb50d0c95b8901e7a21edc57f33f0032e42_Arrows_thin_arrows_all_directions_cross.svg", + "shortDescription": "Change the animation according to the movement direction.", + "version": "0.1.0", + "description": "Change the animation according to the movement direction.", + "tags": [ + "animation", + "direction" + ], + "authorIds": [ + "IWykYNRvhCZBN3vEgKEbBPOR3Oc2" + ], "dependencies": [], - "eventsFunctions": [ + "eventsFunctions": [], + "eventsBasedBehaviors": [ { - "description": "Choose the animation according to the object movement.", - "fullName": "Choose animation according to movement", - "functionType": "Action", - "name": "ChooseAnimationDirection", - "sentence": "Choose the animation of _PARAM1_ according to the movement", - "events": [ - { - "type": "BuiltinCommonInstructions::Comment", - "color": { - "b": 109, - "g": 230, - "r": 255, - "textB": 0, - "textG": 0, - "textR": 0 - }, - "comment": "When moving, set the animation according to the direction of the movement (we can automatically compute it. For example, if the angle is 180 degrees (i.e: left), the direction will be 1 + 180/45 = 5). This allow us to make only one action, rather than adding conditions for every direction.\nThis supposes that animation #0 is the Idle animation, and the others animation are in the right order (animation #1 is the right, and then ordered in a clock wise manner).", - "comment2": "" - }, + "description": "Change the animation according to the movement direction.", + "fullName": "Top-down movement animator", + "name": "TopDownMovementAnimator", + "objectType": "Sprite", + "eventsFunctions": [ { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [ + "fullName": "", + "functionType": "Action", + "name": "onCreated", + "sentence": "", + "events": [ { - "type": { - "value": "TopDownMovementBehavior::IsMoving" - }, - "parameters": [ - "Mindy", - "TopDownMovement" + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::PropertyDirectionCount" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "0" + ] + } + ], + "actions": [], + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementBehavior::DiagonalsAllowed" + }, + "parameters": [ + "Object", + "TopDownMovement" + ] + } + ], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetPropertyDirectionCount" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "8" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "inverted": true, + "value": "TopDownMovementBehavior::DiagonalsAllowed" + }, + "parameters": [ + "Object", + "TopDownMovement" + ] + } + ], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetPropertyDirectionCount" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "4" + ] + } + ] + } ] } ], - "actions": [ - { - "type": { - "value": "ChangeAnimation" - }, - "parameters": [ - "Mindy", - "=", - "1 + mod(round((Mindy.TopDownMovement::Angle())/45+1), 8)" - ] - } - ] - }, - { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [ + "parameters": [ { - "type": { - "value": "BehaviorActivated" - }, - "parameters": [ - "Mindy", - "NavMeshPathfindingBehavior" - ] + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" }, { - "type": { - "value": "NavMeshPathfinding::NavMeshPathfindingBehavior::IsMoving" - }, - "parameters": [ - "Mindy", - "NavMeshPathfindingBehavior" - ] + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" } ], - "actions": [ - { - "type": { - "value": "ChangeAnimation" - }, - "parameters": [ - "Mindy", - "=", - "1 + mod(round((Mindy.NavMeshPathfindingBehavior::MovementAngle())/45), 8)" - ] - } - ] + "objectGroups": [] }, { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [ + "fullName": "", + "functionType": "Action", + "name": "onActivate", + "sentence": "", + "events": [ { - "type": { - "inverted": true, - "value": "CharacterMovement::IsMoving" - }, - "parameters": [ - "Mindy", - "Mindy", - "NavMeshPathfindingBehavior", - "TopDownMovement", - "" + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetAnimationDirection" + }, + "parameters": [ + "Object", + "Behavior", + "Object.Behavior::Direction()", + "" + ] + } ] } ], - "actions": [ + "parameters": [ { - "type": { - "value": "ChangeAnimation" - }, - "parameters": [ - "Mindy", - "=", - "0" - ] + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" } - ] - } - ], - "parameters": [ - { - "description": "Object", - "name": "Mindy", - "supplementaryInformation": "Sprite", - "type": "objectList" - }, - { - "description": "Pathinding", - "name": "NavMeshPathfindingBehavior", - "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingBehavior", - "type": "behavior" + ], + "objectGroups": [] }, { - "description": "Top-down movement", - "name": "TopDownMovement", - "supplementaryInformation": "TopDownMovementBehavior::TopDownMovementBehavior", + "fullName": "", + "functionType": "Action", + "name": "doStepPostEvents", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementBehavior::Speed" + }, + "parameters": [ + "Object", + "TopDownMovement", + "=", + "0" + ] + } + ], + "actions": [ + { + "type": { + "value": "PauseAnimation" + }, + "parameters": [ + "Object" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementBehavior::Speed" + }, + "parameters": [ + "Object", + "TopDownMovement", + ">", + "0" + ] + } + ], + "actions": [ + { + "type": { + "value": "PlayAnimation" + }, + "parameters": [ + "Object" + ] + } + ], + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::PropertyIsScalingAnimation" + }, + "parameters": [ + "Object", + "Behavior" + ] + } + ], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetAnimationSpeedScale" + }, + "parameters": [ + "Object", + "Behavior", + "" + ] + } + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetSharedPropertyNewAnimationDirection" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "Object.Behavior::Direction()" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Comment", + "color": { + "b": 109, + "g": 230, + "r": 255, + "textB": 0, + "textG": 0, + "textR": 0 + }, + "comment": "Use a small margin is used to avoid to flicker between 2 directions.", + "comment2": "" + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "inverted": true, + "value": "BuiltinCommonInstructions::CompareNumbers" + }, + "parameters": [ + "abs(mod(Object.Behavior::SharedPropertyNewAnimationDirection() - Object.Behavior::PropertyAnimationDirection(), Object.Behavior::PropertyDirectionCount()))", + ">", + "0.5 + 0.0625" + ] + } + ], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetAnimationDirection" + }, + "parameters": [ + "Object", + "Behavior", + "Object.Behavior::SharedPropertyNewAnimationDirection()", + "" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "description": "the animation name of the object.", + "fullName": "Animation name", + "functionType": "ExpressionAndCondition", + "name": "AnimationName", + "sentence": "the animation name", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetReturnString" + }, + "parameters": [ + "Object.Behavior::PropertyAnimationName()" + ] + } + ] + } + ], + "expressionType": { + "type": "string" + }, + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "fullName": "", + "functionType": "ActionWithOperator", + "getterName": "AnimationName", + "name": "SetAnimationName", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::PropertyAnimationName" + }, + "parameters": [ + "Object", + "Behavior", + "!=", + "GetArgumentAsString(\"Value\")" + ] + } + ], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetPropertyAnimationName" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "GetArgumentAsString(\"Value\")" + ] + }, + { + "type": { + "value": "SetAnimationName" + }, + "parameters": [ + "Object", + "Object. Behavior::PropertyAnimationName() + ToString(Object.Behavior::PropertyAnimationDirection())" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "description": "Check if the animation is scaled according to speed.", + "fullName": "Scale animation according to speed", + "functionType": "Condition", + "name": "IsScalingAnimation", + "sentence": "_PARAM0_ animation is scaled according to speed", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::PropertyIsScalingAnimation" + }, + "parameters": [ + "Object", + "Behavior" + ] + } + ], + "actions": [ + { + "type": { + "value": "SetReturnBoolean" + }, + "parameters": [ + "True" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "description": "Change whether the animation is scaled according to speed or not.", + "fullName": "Scale animation according to speed", + "functionType": "Action", + "name": "SetIsScalingAnimation", + "sentence": "Scale the animation of _PARAM0_ according to speed: _PARAM2_", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "inverted": true, + "value": "GetArgumentAsBoolean" + }, + "parameters": [ + "\"Value\"" + ] + } + ], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetPropertyIsScalingAnimation" + }, + "parameters": [ + "Object", + "Behavior", + "no" + ] + }, + { + "type": { + "value": "ChangeAnimationSpeedScale" + }, + "parameters": [ + "Object", + "=", + "1" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "GetArgumentAsBoolean" + }, + "parameters": [ + "\"Value\"" + ] + } + ], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetPropertyIsScalingAnimation" + }, + "parameters": [ + "Object", + "Behavior", + "yes" + ] + }, + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetAnimationSpeedScale" + }, + "parameters": [ + "Object", + "Behavior", + "" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + }, + { + "defaultValue": "yes", + "description": "IsScalingAnimation", + "name": "Value", + "optional": true, + "type": "yesorno" + } + ], + "objectGroups": [] + }, + { + "description": "Change the animation speed scale according to the object speed.", + "fullName": "Animation speed scale", + "functionType": "Action", + "name": "SetAnimationSpeedScale", + "private": true, + "sentence": "Change the animation speed scale according to _PARAM0_ speed", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "ChangeAnimationSpeedScale" + }, + "parameters": [ + "Object", + "=", + "Object.TopDownMovement::Speed() / Object.TopDownMovement::MaxSpeed()" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "description": "Return the object movement direction.", + "fullName": "Direction", + "functionType": "Expression", + "name": "Direction", + "private": true, + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetReturnNumber" + }, + "parameters": [ + "mod((Object.TopDownMovement::Angle() + Object.Behavior::PropertyAngleOffset()) * Object.Behavior::PropertyDirectionCount() / 360, Object.Behavior::PropertyDirectionCount())" + ] + } + ] + } + ], + "expressionType": { + "type": "expression" + }, + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "description": "Change the animation direction of the object.", + "fullName": "Animation direction", + "functionType": "Action", + "name": "SetAnimationDirection", + "private": true, + "sentence": "Change the animation direction of _PARAM0_ to _PARAM2_", + "events": [ + { + "type": "BuiltinCommonInstructions::Comment", + "color": { + "b": 109, + "g": 230, + "r": 255, + "textB": 0, + "textG": 0, + "textR": 0 + }, + "comment": "Change the animation but keep the current frame number.", + "comment2": "" + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetPropertyAnimationDirection" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "round(GetArgumentAsNumber(\"Value\"))" + ] + }, + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetSharedPropertyAnimationFrame" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "Object.Sprite()" + ] + }, + { + "type": { + "value": "SetAnimationName" + }, + "parameters": [ + "Object", + "Object. Behavior::PropertyAnimationName() + ToString(Object.Behavior::PropertyAnimationDirection())" + ] + }, + { + "type": { + "value": "ChangeSprite" + }, + "parameters": [ + "Object", + "=", + "Object.Behavior::SharedPropertyAnimationFrame()" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + }, + { + "description": "Value", + "name": "Value", + "type": "expression" + } + ], + "objectGroups": [] + } + ], + "propertyDescriptors": [ + { + "value": "", + "type": "Behavior", + "label": "Top-down movement", + "description": "", + "group": "", + "extraInformation": [ + "TopDownMovementBehavior::TopDownMovementBehavior" + ], + "hidden": false, + "name": "TopDownMovement" + }, + { + "value": "true", + "type": "Boolean", + "label": "Scale animation according to speed", + "description": "", + "group": "Animation", + "extraInformation": [], + "hidden": false, + "name": "IsScalingAnimation" + }, + { + "value": "Walk", + "type": "String", + "label": "Animation name", + "description": "Animations must be called \"Walk0\", \"Walk1\"... for left, down...", + "group": "Animation", + "extraInformation": [], + "hidden": false, + "name": "AnimationName" + }, + { + "value": "0", + "type": "Number", + "unit": "Dimensionless", + "label": "Number of directions", + "description": "Leave to 0 to automatically use 8 when diagonals are allowed and 4 otherwise.", + "group": "Direction", + "extraInformation": [], + "hidden": false, + "name": "DirectionCount" + }, + { + "value": "0", + "type": "Number", + "unit": "DegreeAngle", + "label": "Angle offset", + "description": "Setted to 90°, \"Walk0\" becomes the animation for down.", + "group": "Direction", + "extraInformation": [], + "hidden": false, + "name": "AngleOffset" + }, + { + "value": "0", + "type": "Number", + "label": "", + "description": "", + "group": "", + "extraInformation": [], + "hidden": true, + "name": "AnimationDirection" + } + ], + "sharedPropertyDescriptors": [ + { + "value": "0", + "type": "Number", + "label": "", + "description": "", + "group": "", + "extraInformation": [], + "hidden": true, + "name": "NewAnimationDirection" + }, + { + "value": "0", + "type": "Number", + "label": "", + "description": "", + "group": "", + "extraInformation": [], + "hidden": true, + "name": "AnimationFrame" + } + ] + } + ], + "eventsBasedObjects": [] + }, + { + "author": "", + "category": "", + "extensionNamespace": "", + "fullName": "CharacterMovement", + "helpPath": "", + "iconUrl": "", + "name": "CharacterMovement", + "previewIconUrl": "", + "shortDescription": "", + "version": "", + "description": "Originally automatically extracted from events of the project", + "tags": [], + "authorIds": [], + "dependencies": [], + "eventsFunctions": [ + { + "description": "Choose the animation according to the object movement.", + "fullName": "Choose animation according to movement", + "functionType": "Action", + "name": "ChooseAnimationDirection", + "sentence": "Choose the animation of _PARAM1_ according to the movement", + "events": [ + { + "type": "BuiltinCommonInstructions::Comment", + "color": { + "b": 109, + "g": 230, + "r": 255, + "textB": 0, + "textG": 0, + "textR": 0 + }, + "comment": "When moving, set the animation according to the direction of the movement (we can automatically compute it. For example, if the angle is 180 degrees (i.e: left), the direction will be 1 + 180/45 = 5). This allow us to make only one action, rather than adding conditions for every direction.\nThis supposes that animation #0 is the Idle animation, and the others animation are in the right order (animation #1 is the right, and then ordered in a clock wise manner).", + "comment2": "" + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "inverted": true, + "value": "TopDownMovementBehavior::IsMoving" + }, + "parameters": [ + "Mindy", + "TopDownMovement" + ] + } + ], + "actions": [ + { + "type": { + "value": "ActivateBehavior" + }, + "parameters": [ + "Mindy", + "TopDownAnimator", + "no" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementBehavior::IsMoving" + }, + "parameters": [ + "Mindy", + "TopDownMovement" + ] + } + ], + "actions": [ + { + "type": { + "value": "ActivateBehavior" + }, + "parameters": [ + "Mindy", + "TopDownAnimator", + "yes" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "BehaviorActivated" + }, + "parameters": [ + "Mindy", + "NavMeshPathfindingBehavior" + ] + }, + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingBehavior::IsMoving" + }, + "parameters": [ + "Mindy", + "NavMeshPathfindingBehavior" + ] + } + ], + "actions": [ + { + "type": { + "value": "ChangeAnimation" + }, + "parameters": [ + "Mindy", + "=", + "1 + mod(round((Mindy.NavMeshPathfindingBehavior::MovementAngle())/45), 8)" + ] + }, + { + "type": { + "value": "PlayAnimation" + }, + "parameters": [ + "Mindy" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "inverted": true, + "value": "CharacterMovement::IsMoving" + }, + "parameters": [ + "Mindy", + "Mindy", + "NavMeshPathfindingBehavior", + "TopDownMovement", + "" + ] + } + ], + "actions": [ + { + "type": { + "value": "ChangeAnimation" + }, + "parameters": [ + "Mindy", + "=", + "0" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Mindy", + "supplementaryInformation": "Sprite", + "type": "objectList" + }, + { + "description": "Pathinding", + "name": "NavMeshPathfindingBehavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingBehavior", + "type": "behavior" + }, + { + "description": "Top-down movement", + "name": "TopDownMovement", + "supplementaryInformation": "TopDownMovementBehavior::TopDownMovementBehavior", + "type": "behavior" + }, + { + "description": "Top-down movement animator", + "name": "TopDownAnimator", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", "type": "behavior" } ], From 5ea16e8920f3683902c9de63a0491d026418f805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davy=20H=C3=A9lard?= Date: Sun, 12 Mar 2023 16:15:38 +0100 Subject: [PATCH 2/7] Upgrade the NavMesh extension. --- examples/isometric-game/isometric-game.json | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/isometric-game/isometric-game.json b/examples/isometric-game/isometric-game.json index 3e1fb718e..c99a0a2e8 100644 --- a/examples/isometric-game/isometric-game.json +++ b/examples/isometric-game/isometric-game.json @@ -34729,9 +34729,14 @@ "description": [ "In comparison to the built-in pathfinding behavior, this one aims to:", "- better respect obstacle shapes", - "- find pathes faster if obstacles don't move", - "" + "- find paths faster if obstacles don't move", + "", + "The isometric example shows how to use this extension to move a character to a destination ([open the project online](https://editor.gdevelop.io/?project=example://isometric-game))." ], + "origin": { + "identifier": "NavMeshPathfinding", + "name": "gdevelop-extension-store" + }, "tags": [ "navmesh", "pathfinding" From 135f5356ea50e35e0947f8a4519999fb6a2b5c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davy=20H=C3=A9lard?= Date: Sun, 12 Mar 2023 16:19:59 +0100 Subject: [PATCH 3/7] Handle obstacle deletion. --- examples/isometric-game/isometric-game.json | 105 ++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/examples/isometric-game/isometric-game.json b/examples/isometric-game/isometric-game.json index c99a0a2e8..127223686 100644 --- a/examples/isometric-game/isometric-game.json +++ b/examples/isometric-game/isometric-game.json @@ -40893,6 +40893,111 @@ ], "objectGroups": [] }, + { + "fullName": "", + "functionType": "Action", + "name": "onDeActivate", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::JsCode", + "inlineCode": [ + "const object = objects[0];\r", + "const behaviorName = eventsFunctionContext.getBehaviorName(\"Behavior\");\r", + "const behavior = object.getBehavior(behaviorName);\r", + "\r", + "behavior.__NavMeshPathfinding.obstacle.onDeActivate();" + ], + "parameterObjects": "Object", + "useStrict": true, + "eventsSheetExpanded": true + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingObstacleBehavior", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "fullName": "", + "functionType": "Action", + "name": "onActivate", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::JsCode", + "inlineCode": [ + "const object = objects[0];\r", + "const behaviorName = eventsFunctionContext.getBehaviorName(\"Behavior\");\r", + "const behavior = object.getBehavior(behaviorName);\r", + "\r", + "behavior.__NavMeshPathfinding.obstacle.onActivate();" + ], + "parameterObjects": "Object", + "useStrict": true, + "eventsSheetExpanded": true + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingObstacleBehavior", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "fullName": "", + "functionType": "Action", + "name": "onDestroy", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::JsCode", + "inlineCode": [ + "const object = objects[0];\r", + "const behaviorName = eventsFunctionContext.getBehaviorName(\"Behavior\");\r", + "const behavior = object.getBehavior(behaviorName);\r", + "\r", + "behavior.__NavMeshPathfinding.obstacle.onDestroy();" + ], + "parameterObjects": "Object", + "useStrict": true, + "eventsSheetExpanded": true + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingObstacleBehavior", + "type": "behavior" + } + ], + "objectGroups": [] + }, { "description": "the cell size for obstacle collision mask rasterization. While an object is needed, this will apply to all objects using the behavior.", "fullName": "Cell size", From da49c01f7597f0c7386e8e970bb673be2ba6673a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davy=20H=C3=A9lard?= Date: Sun, 12 Mar 2023 16:56:32 +0100 Subject: [PATCH 4/7] Add a animator behavior for the path finding. --- examples/isometric-game/isometric-game.json | 904 +++++++++++++++++++- 1 file changed, 893 insertions(+), 11 deletions(-) diff --git a/examples/isometric-game/isometric-game.json b/examples/isometric-game/isometric-game.json index 127223686..3c25d23f1 100644 --- a/examples/isometric-game/isometric-game.json +++ b/examples/isometric-game/isometric-game.json @@ -8267,6 +8267,16 @@ "variables": [], "effects": [], "behaviors": [ + { + "name": "NavMeshPathfindingAnimator", + "type": "NavMeshPathfinding::NavMeshPathfindingAnimator", + "NavMeshPathfinding": "NavMeshPathfindingBehavior", + "IsScalingAnimation": true, + "AnimationName": "Walk", + "DirectionCount": 8, + "AngleOffset": 0, + "AnimationDirection": 0 + }, { "name": "NavMeshPathfindingBehavior", "type": "NavMeshPathfinding::NavMeshPathfindingBehavior", @@ -28118,6 +28128,12 @@ } ], "behaviorsSharedData": [ + { + "name": "NavMeshPathfindingAnimator", + "type": "NavMeshPathfinding::NavMeshPathfindingAnimator", + "NewAnimationDirection": 0, + "AnimationFrame": 0 + }, { "name": "NavMeshPathfindingBehavior", "type": "NavMeshPathfinding::NavMeshPathfindingBehavior" @@ -29100,6 +29116,51 @@ } ] }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "BuiltinCommonInstructions::Or" + }, + "parameters": [], + "subInstructions": [ + { + "type": { + "inverted": true, + "value": "BehaviorActivated" + }, + "parameters": [ + "Mindy", + "NavMeshPathfindingBehavior" + ] + }, + { + "type": { + "inverted": true, + "value": "NavMeshPathfinding::NavMeshPathfindingBehavior::IsMoving" + }, + "parameters": [ + "Mindy", + "NavMeshPathfindingBehavior" + ] + } + ] + } + ], + "actions": [ + { + "type": { + "value": "ActivateBehavior" + }, + "parameters": [ + "Mindy", + "PathfindingAnimator", + "no" + ] + } + ] + }, { "type": "BuiltinCommonInstructions::Standard", "conditions": [ @@ -29125,20 +29186,12 @@ "actions": [ { "type": { - "value": "ChangeAnimation" + "value": "ActivateBehavior" }, "parameters": [ "Mindy", - "=", - "1 + mod(round((Mindy.NavMeshPathfindingBehavior::MovementAngle())/45), 8)" - ] - }, - { - "type": { - "value": "PlayAnimation" - }, - "parameters": [ - "Mindy" + "PathfindingAnimator", + "yes" ] } ] @@ -29198,6 +29251,12 @@ "name": "TopDownAnimator", "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", "type": "behavior" + }, + { + "description": "Navigation mesh pathfinding animator", + "name": "PathfindingAnimator", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingAnimator", + "type": "behavior" } ], "objectGroups": [] @@ -41569,6 +41628,829 @@ "name": "IsometricRatio" } ] + }, + { + "description": "Change the animation according to the movement direction.", + "fullName": "Navigation mesh pathfinding animator", + "name": "NavMeshPathfindingAnimator", + "objectType": "Sprite", + "eventsFunctions": [ + { + "fullName": "", + "functionType": "Action", + "name": "onCreated", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::PropertyDirectionCount" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "0" + ] + } + ], + "actions": [], + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementBehavior::DiagonalsAllowed" + }, + "parameters": [ + "Object", + "NavMeshPathfinding" + ] + } + ], + "actions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::SetPropertyDirectionCount" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "8" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "inverted": true, + "value": "TopDownMovementBehavior::DiagonalsAllowed" + }, + "parameters": [ + "Object", + "NavMeshPathfinding" + ] + } + ], + "actions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::SetPropertyDirectionCount" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "4" + ] + } + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "fullName": "", + "functionType": "Action", + "name": "onActivate", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::SetAnimationDirection" + }, + "parameters": [ + "Object", + "Behavior", + "Object.Behavior::Direction()", + "" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "fullName": "", + "functionType": "Action", + "name": "doStepPostEvents", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingBehavior::Speed" + }, + "parameters": [ + "Object", + "NavMeshPathfinding", + "=", + "0", + "" + ] + } + ], + "actions": [ + { + "type": { + "value": "PauseAnimation" + }, + "parameters": [ + "Object" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingBehavior::Speed" + }, + "parameters": [ + "Object", + "NavMeshPathfinding", + ">", + "0", + "" + ] + } + ], + "actions": [ + { + "type": { + "value": "PlayAnimation" + }, + "parameters": [ + "Object" + ] + } + ], + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::PropertyIsScalingAnimation" + }, + "parameters": [ + "Object", + "Behavior" + ] + } + ], + "actions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::SetAnimationSpeedScale" + }, + "parameters": [ + "Object", + "Behavior", + "" + ] + } + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::SetSharedPropertyNewAnimationDirection" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "Object.Behavior::Direction()" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Comment", + "color": { + "b": 109, + "g": 230, + "r": 255, + "textB": 0, + "textG": 0, + "textR": 0 + }, + "comment": "Use a small margin is used to avoid to flicker between 2 directions.", + "comment2": "" + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "inverted": true, + "value": "BuiltinCommonInstructions::CompareNumbers" + }, + "parameters": [ + "abs(mod(Object.Behavior::SharedPropertyNewAnimationDirection() - Object.Behavior::PropertyAnimationDirection(), Object.Behavior::PropertyDirectionCount()))", + ">", + "0.5 + 0.0625" + ] + } + ], + "actions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::SetAnimationDirection" + }, + "parameters": [ + "Object", + "Behavior", + "Object.Behavior::SharedPropertyNewAnimationDirection()", + "" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "description": "the animation name of the object.", + "fullName": "Animation name", + "functionType": "ExpressionAndCondition", + "name": "AnimationName", + "sentence": "the animation name", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetReturnString" + }, + "parameters": [ + "Object.Behavior::PropertyAnimationName()" + ] + } + ] + } + ], + "expressionType": { + "type": "string" + }, + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "fullName": "", + "functionType": "ActionWithOperator", + "getterName": "AnimationName", + "name": "SetAnimationName", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::PropertyAnimationName" + }, + "parameters": [ + "Object", + "Behavior", + "!=", + "GetArgumentAsString(\"Value\")" + ] + } + ], + "actions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::SetPropertyAnimationName" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "GetArgumentAsString(\"Value\")" + ] + }, + { + "type": { + "value": "SetAnimationName" + }, + "parameters": [ + "Object", + "Object. Behavior::PropertyAnimationName() + ToString(Object.Behavior::PropertyAnimationDirection())" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "description": "Check if the animation is scaled according to speed.", + "fullName": "Scale animation according to speed", + "functionType": "Condition", + "name": "IsScalingAnimation", + "sentence": "_PARAM0_ animation is scaled according to speed", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::PropertyIsScalingAnimation" + }, + "parameters": [ + "Object", + "Behavior" + ] + } + ], + "actions": [ + { + "type": { + "value": "SetReturnBoolean" + }, + "parameters": [ + "True" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "description": "Change whether the animation is scaled according to speed or not.", + "fullName": "Scale animation according to speed", + "functionType": "Action", + "name": "SetIsScalingAnimation", + "sentence": "Scale the animation of _PARAM0_ according to speed: _PARAM2_", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "inverted": true, + "value": "GetArgumentAsBoolean" + }, + "parameters": [ + "\"Value\"" + ] + } + ], + "actions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::SetPropertyIsScalingAnimation" + }, + "parameters": [ + "Object", + "Behavior", + "no" + ] + }, + { + "type": { + "value": "ChangeAnimationSpeedScale" + }, + "parameters": [ + "Object", + "=", + "1" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "GetArgumentAsBoolean" + }, + "parameters": [ + "\"Value\"" + ] + } + ], + "actions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::SetPropertyIsScalingAnimation" + }, + "parameters": [ + "Object", + "Behavior", + "yes" + ] + }, + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::SetAnimationSpeedScale" + }, + "parameters": [ + "Object", + "Behavior", + "" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingAnimator", + "type": "behavior" + }, + { + "defaultValue": "yes", + "description": "IsScalingAnimation", + "name": "Value", + "optional": true, + "type": "yesorno" + } + ], + "objectGroups": [] + }, + { + "description": "Change the animation speed scale according to the object speed.", + "fullName": "Animation speed scale", + "functionType": "Action", + "name": "SetAnimationSpeedScale", + "private": true, + "sentence": "Change the animation speed scale according to _PARAM0_ speed", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "ChangeAnimationSpeedScale" + }, + "parameters": [ + "Object", + "=", + "Object.NavMeshPathfinding::Speed() / Object.NavMeshPathfinding::MaxSpeed()" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "description": "Return the object movement direction.", + "fullName": "Direction", + "functionType": "Expression", + "name": "Direction", + "private": true, + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetReturnNumber" + }, + "parameters": [ + "mod((Object.NavMeshPathfinding::MovementAngle() + Object.Behavior::PropertyAngleOffset()) * Object.Behavior::PropertyDirectionCount() / 360, Object.Behavior::PropertyDirectionCount())" + ] + } + ] + } + ], + "expressionType": { + "type": "expression" + }, + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "description": "Change the animation direction of the object.", + "fullName": "Animation direction", + "functionType": "Action", + "name": "SetAnimationDirection", + "private": true, + "sentence": "Change the animation direction of _PARAM0_ to _PARAM2_", + "events": [ + { + "type": "BuiltinCommonInstructions::Comment", + "color": { + "b": 109, + "g": 230, + "r": 255, + "textB": 0, + "textG": 0, + "textR": 0 + }, + "comment": "Change the animation but keep the current frame number.", + "comment2": "" + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::SetPropertyAnimationDirection" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "round(GetArgumentAsNumber(\"Value\"))" + ] + }, + { + "type": { + "value": "NavMeshPathfinding::NavMeshPathfindingAnimator::SetSharedPropertyAnimationFrame" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "Object.Sprite()" + ] + }, + { + "type": { + "value": "SetAnimationName" + }, + "parameters": [ + "Object", + "Object. Behavior::PropertyAnimationName() + ToString(Object.Behavior::PropertyAnimationDirection())" + ] + }, + { + "type": { + "value": "ChangeSprite" + }, + "parameters": [ + "Object", + "=", + "Object.Behavior::SharedPropertyAnimationFrame()" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingAnimator", + "type": "behavior" + }, + { + "description": "Value", + "name": "Value", + "type": "expression" + } + ], + "objectGroups": [] + } + ], + "propertyDescriptors": [ + { + "value": "", + "type": "Behavior", + "label": "Navigation mesh pathfinding", + "description": "", + "group": "", + "extraInformation": [ + "NavMeshPathfinding::NavMeshPathfindingBehavior" + ], + "hidden": false, + "name": "NavMeshPathfinding" + }, + { + "value": "true", + "type": "Boolean", + "label": "Scale animation according to speed", + "description": "", + "group": "Animation", + "extraInformation": [], + "hidden": false, + "name": "IsScalingAnimation" + }, + { + "value": "Walk", + "type": "String", + "label": "Animation name", + "description": "Animations must be called \"Walk0\", \"Walk1\"... for left, down...", + "group": "Animation", + "extraInformation": [], + "hidden": false, + "name": "AnimationName" + }, + { + "value": "0", + "type": "Number", + "unit": "Dimensionless", + "label": "Number of directions", + "description": "Leave to 0 to automatically use 8 when diagonals are allowed and 4 otherwise.", + "group": "Direction", + "extraInformation": [], + "hidden": false, + "name": "DirectionCount" + }, + { + "value": "0", + "type": "Number", + "unit": "DegreeAngle", + "label": "Angle offset", + "description": "Setted to 90°, \"Walk0\" becomes the animation for down.", + "group": "Direction", + "extraInformation": [], + "hidden": false, + "name": "AngleOffset" + }, + { + "value": "0", + "type": "Number", + "label": "", + "description": "", + "group": "", + "extraInformation": [], + "hidden": true, + "name": "AnimationDirection" + } + ], + "sharedPropertyDescriptors": [ + { + "value": "0", + "type": "Number", + "label": "", + "description": "", + "group": "", + "extraInformation": [], + "hidden": true, + "name": "NewAnimationDirection" + }, + { + "value": "0", + "type": "Number", + "label": "", + "description": "", + "group": "", + "extraInformation": [], + "hidden": true, + "name": "AnimationFrame" + } + ] } ], "eventsBasedObjects": [] From 2db2c97c85436543fb1dd5a7e946bb4122638a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davy=20H=C3=A9lard?= Date: Sun, 12 Mar 2023 18:22:28 +0100 Subject: [PATCH 5/7] Fix the animator behaviors. --- examples/isometric-game/isometric-game.json | 141 ++++++++++++++++---- 1 file changed, 116 insertions(+), 25 deletions(-) diff --git a/examples/isometric-game/isometric-game.json b/examples/isometric-game/isometric-game.json index 3c25d23f1..f8300561d 100644 --- a/examples/isometric-game/isometric-game.json +++ b/examples/isometric-game/isometric-game.json @@ -8381,7 +8381,7 @@ ], "animations": [ { - "name": "idle", + "name": "Idle", "useMultipleDirections": false, "directions": [ { @@ -27798,6 +27798,7 @@ "NavMeshPathfindingBehavior", "TopDownMovement", "TopDownMovementAnimator", + "NavMeshPathfindingAnimator", "" ] } @@ -28471,9 +28472,9 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "abs(mod(Object.Behavior::SharedPropertyNewAnimationDirection() - Object.Behavior::PropertyAnimationDirection(), Object.Behavior::PropertyDirectionCount()))", + "abs(Object.Behavior:: DirectionDifference(Object.Behavior::SharedPropertyNewAnimationDirection(), Object.Behavior::PropertyAnimationDirection()))", ">", - "0.5 + 0.0625" + "0.5 + 0.03125" ] } ], @@ -28819,7 +28820,7 @@ "value": "SetReturnNumber" }, "parameters": [ - "mod((Object.TopDownMovement::Angle() + Object.Behavior::PropertyAngleOffset()) * Object.Behavior::PropertyDirectionCount() / 360, Object.Behavior::PropertyDirectionCount())" + "(Object.TopDownMovement::Angle() + Object.Behavior::PropertyAngleOffset()) * Object.Behavior::PropertyDirectionCount() / 360" ] } ] @@ -28844,6 +28845,58 @@ ], "objectGroups": [] }, + { + "description": "Return the difference between 2 directions.", + "fullName": "Direction dirrerence", + "functionType": "Expression", + "name": "DirectionDifference", + "private": true, + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetReturnNumber" + }, + "parameters": [ + "mod(mod(GetArgumentAsNumber(\"Direction\") - GetArgumentAsNumber(\"OtherDirection\"), Object.Behavior::PropertyDirectionCount()) + Object.Behavior::PropertyDirectionCount() / 2, Object.Behavior::PropertyDirectionCount()) - Object.Behavior::PropertyDirectionCount() / 2" + ] + } + ] + } + ], + "expressionType": { + "type": "expression" + }, + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + }, + { + "description": "Direction", + "name": "Direction", + "type": "expression" + }, + { + "description": "Other direction", + "name": "OtherDirection", + "type": "expression" + } + ], + "objectGroups": [] + }, { "description": "Change the animation direction of the object.", "fullName": "Animation direction", @@ -28877,7 +28930,7 @@ "Object", "Behavior", "=", - "round(GetArgumentAsNumber(\"Value\"))" + "mod(mod(round(GetArgumentAsNumber(\"Value\")), Object.Behavior::PropertyDirectionCount()) + Object.Behavior::PropertyDirectionCount(), Object.Behavior::PropertyDirectionCount())" ] }, { @@ -29050,19 +29103,6 @@ "name": "ChooseAnimationDirection", "sentence": "Choose the animation of _PARAM1_ according to the movement", "events": [ - { - "type": "BuiltinCommonInstructions::Comment", - "color": { - "b": 109, - "g": 230, - "r": 255, - "textB": 0, - "textG": 0, - "textR": 0 - }, - "comment": "When moving, set the animation according to the direction of the movement (we can automatically compute it. For example, if the angle is 180 degrees (i.e: left), the direction will be 1 + 180/45 = 5). This allow us to make only one action, rather than adding conditions for every direction.\nThis supposes that animation #0 is the Idle animation, and the others animation are in the right order (animation #1 is the right, and then ordered in a clock wise manner).", - "comment2": "" - }, { "type": "BuiltinCommonInstructions::Standard", "conditions": [ @@ -29216,12 +29256,11 @@ "actions": [ { "type": { - "value": "ChangeAnimation" + "value": "SetAnimationName" }, "parameters": [ "Mindy", - "=", - "0" + "\"Idle\"" ] } ] @@ -41899,9 +41938,9 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "abs(mod(Object.Behavior::SharedPropertyNewAnimationDirection() - Object.Behavior::PropertyAnimationDirection(), Object.Behavior::PropertyDirectionCount()))", + "abs(Object.Behavior:: DirectionDifference(Object.Behavior::SharedPropertyNewAnimationDirection(), Object.Behavior::PropertyAnimationDirection()))", ">", - "0.5 + 0.0625" + "0.5 + 0.03125" ] } ], @@ -42247,7 +42286,7 @@ "value": "SetReturnNumber" }, "parameters": [ - "mod((Object.NavMeshPathfinding::MovementAngle() + Object.Behavior::PropertyAngleOffset()) * Object.Behavior::PropertyDirectionCount() / 360, Object.Behavior::PropertyDirectionCount())" + "(Object.NavMeshPathfinding::MovementAngle() + Object.Behavior::PropertyAngleOffset()) * Object.Behavior::PropertyDirectionCount() / 360" ] } ] @@ -42272,6 +42311,58 @@ ], "objectGroups": [] }, + { + "description": "Return the difference between 2 directions.", + "fullName": "Direction dirrerence", + "functionType": "Expression", + "name": "DirectionDifference", + "private": true, + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetReturnNumber" + }, + "parameters": [ + "mod(mod(GetArgumentAsNumber(\"Direction\") - GetArgumentAsNumber(\"OtherDirection\"), Object.Behavior::PropertyDirectionCount()) + Object.Behavior::PropertyDirectionCount() / 2, Object.Behavior::PropertyDirectionCount()) - Object.Behavior::PropertyDirectionCount() / 2" + ] + } + ] + } + ], + "expressionType": { + "type": "expression" + }, + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "NavMeshPathfinding::NavMeshPathfindingAnimator", + "type": "behavior" + }, + { + "description": "Direction", + "name": "Direction", + "type": "expression" + }, + { + "description": "Other direction", + "name": "OtherDirection", + "type": "expression" + } + ], + "objectGroups": [] + }, { "description": "Change the animation direction of the object.", "fullName": "Animation direction", @@ -42305,7 +42396,7 @@ "Object", "Behavior", "=", - "round(GetArgumentAsNumber(\"Value\"))" + "mod(mod(round(GetArgumentAsNumber(\"Value\")), Object.Behavior::PropertyDirectionCount()) + Object.Behavior::PropertyDirectionCount(), Object.Behavior::PropertyDirectionCount())" ] }, { From cb83175936232633cbeba15bd469cf0212b35ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davy=20H=C3=A9lard?= Date: Sun, 12 Mar 2023 18:45:45 +0100 Subject: [PATCH 6/7] Increment NavMesh version. --- examples/isometric-game/isometric-game.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/isometric-game/isometric-game.json b/examples/isometric-game/isometric-game.json index f8300561d..c2e7e41ac 100644 --- a/examples/isometric-game/isometric-game.json +++ b/examples/isometric-game/isometric-game.json @@ -34823,7 +34823,7 @@ "name": "NavMeshPathfinding", "previewIconUrl": "https://resources.gdevelop-app.com/assets/Icons/Line Hero Pack/Master/SVG/Maps and Navigation/Maps and Navigation_map_find_search.svg", "shortDescription": "Pathfinding allows to compute an efficient path for objects, avoiding obstacles on the way.", - "version": "0.1.0", + "version": "0.2.0", "description": [ "In comparison to the built-in pathfinding behavior, this one aims to:", "- better respect obstacle shapes", From ec9f4617f97670a9fd13055cea059b13b33f10ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davy=20H=C3=A9lard?= Date: Sun, 12 Mar 2023 18:53:19 +0100 Subject: [PATCH 7/7] Add tags. --- examples/isometric-game/isometric-game.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/isometric-game/isometric-game.json b/examples/isometric-game/isometric-game.json index c2e7e41ac..e466cc43a 100644 --- a/examples/isometric-game/isometric-game.json +++ b/examples/isometric-game/isometric-game.json @@ -34837,7 +34837,12 @@ }, "tags": [ "navmesh", - "pathfinding" + "pathfinding", + "obstacle", + "solid", + "path", + "detour", + "recast" ], "authorIds": [ "IWykYNRvhCZBN3vEgKEbBPOR3Oc2"