8/17/2023 0 Comments Unity learn procedural animaition![]() ![]() I create 4 Scriptable Objects with Spider Legs parameters and in each of them slightly changed some values (transition time to new position, max vertical offset, min and max range limits, etc.). Meanwhile other group is restricted to take a step. So 2 spider legs, one from each side of the character, take step simultaneously. If 1 of the legs in the group wants to take a step, the second leg in the same group forced to take a step as well. It solved some problems but not all of them (they didn’t detach altogether anymore, but still could mess up the order of the legs to take a step).Īt the end I created 2 groups of spider legs, each contains 1 leg on the left and 1 on the right. So I had to find a way how to synchronize them.Īt the beginning I tried to move only 1 spider leg at time and put other in the queue to wait until the first one finished. Even worse, sometimes all 4 spider legs decided that right now is a perfect moment to take a step and detached from the surface. Sometimes he performed steps with 2 spider legs on the right then with 2 spider legs on the left. While he was moving on flat surface everything was fine, but after changing surface angle or moving around a corner the relative position of the legs and steps timings went completely off. With 1 spider leg everything looked fine until I attached 4 legs the the main character… To add easing to the leg movement and also define vertical offset from the surface I use Animation Curves in the Inspector. To move target to new position I use coroutine. Looping through LineCasts until it finds any point ![]() Var steps = Mathf.CeilToInt(180 / Mathf.Abs(raycastAngularStep)) Var rot = Quaternion.AngleAxis(raycastAngularStep, transform.forward) Rotate end point to specified angle around root Var linecastStartPos = transform.up * distanceFromRoot Determine start and end point for LineCast _newTargetPosition = transform.TransformPoint(_targetDefaultPosition) Assign default target position as new position The function that implements this approach looks like this: private bool GetNewTargetPosition(float distanceFromRoot) To find this point I’m using sequential LineCast that follows sectors with fixed angular step: Standard SphereCast and CircleCast won’t help us because we need to know exact point on the circle and not inside of it. Instead, we need to draw imaginary circle around spider leg root and find a point where this circle intersects with the surface. StartCoroutine(MovetargetToNewPosition()) īecause the surface that the character is crawling on can be rotated to arbitrary angle we cannot just simply do a raycast up/down/left/right. GetNewTargetPosition(_faultRaycastDistanceFromRoot) ![]() If the target is out of range find new point and take a step If (dist > maxDistanceFromRoot || dist < minDistanceFromRoot) Simplified code for this logic looks like this (in real game it’s a bit more complicated): private void UpdateLeg()įloat dist = (_currentTargetPosition - transform.position).magnitude First of wall we need to keep the target (the tip of the spider leg) in specified range. To start I created 1 single spider leg on a flat horizontal surface. All the following game-logic will be focused on finding proper position for the target on the surface and transitioning to this position in the right moment. Spider leg itself is just IK chain with Empty GameObject called target. I created Scriptable Object that stores all these parameters (later I will explain why I decided to put them inside scriptable object instead of prefab). I listed all the parameters that each spider leg should have. Visually this ability represented with spider legs that grow from the character’s back when he lands on the wall and disappear when he performs wall jump or crawls to stable ground. The walls don’t need to be strictly vertical and ceiling is not necessary horizontal. In King, Witch and Dragon the main character has ability to stick and crawl on the walls and the ceiling. In this devlog I will talk about procedural animations of the main character’s abilities which are completely or partially created and controlled from the code inside Unity. In my previous devlog I explained the main character’s animations that I created in Blender and exported to Unity.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |