Kireita Posted July 25, 2020 Share Posted July 25, 2020 Hello, im trying to switch between animations when pressing a key but it is not working: the only key that works is D because the 'idle' animation is set on layer 0, but the others are not working also the animation does not restart, it looks like it picks it up from a specific point as if the animation is still playing in the background. i saw the examples of 'AnimationAdditive' and 'SimpleAnimationPlayer' but i want to change from 1 animation to the other, not combine them. can somebody help me with this? Link to comment
silent Posted July 27, 2020 Share Posted July 27, 2020 Kireita As far as I can see you got this working (from a discord server). Could you please post a final solution for this task? Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Kireita Posted July 27, 2020 Author Share Posted July 27, 2020 @silent hey, i did manage to it working the way i wanted. here is a snippet of the code: void Update() { forward = Input.IsKeyPressed(simplifiedPlayerController.forwardKey); backward = Input.IsKeyPressed(simplifiedPlayerController.backwardKey); left = Input.IsKeyPressed(simplifiedPlayerController.moveLeftKey); right = Input.IsKeyPressed(simplifiedPlayerController.moveRightKey); jump = Input.IsKeyPressed(simplifiedPlayerController.jumpKey); if (forward || left || right || backward) { WalkForward(); } if (jump) { Jump(); } if (actionKey) { // compute animation time animationTime += 60 * Game.IFps; // set animation frame mesh.SetFrame(animation, animationTime); // get actual animation time after set animationTimeJump float time = mesh.SetFrame(animation, animationTime); // copy layer data to root layer mesh.CopyLayer(-1, animation); // check if animation ended if (time < animationTime) { actionKey = false; instantAnimation = true; } else if (instantAnimation) { actionKey = false; } // reset idle animation animationTimeIdle = 0; } else { idle(); } } public void WalkForward() { if (instantAnimation) { animation = (int)Layer.Walk; actionKey = true; instantAnimation = true; } } public void Jump() { if (instantAnimation) { actionKey = true; animationTime = 0; animation = (int)Layer.Jump; instantAnimation = false; } } public void idle() { animation = (int)Layer.Idle; animationTime = 0; animationTimeIdle += 60 * Game.IFps; // set animation frame mesh.SetFrame(animation, animationTimeIdle); } i wanted the possibility of having a forced animation and instant animations, for example jump cannot be canceled so you need to wait for the animation to end and walk can be overwritten by any other action, its not complete but its a start :D. any suggestions would be very much appreciated and this case can be closed. thank you for the help guys! Link to comment
silent Posted July 28, 2020 Share Posted July 28, 2020 In attachment you can find quick and dirty prototype of the forced animation playing: component_animation.zip 2 How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
astressence Posted December 5, 2020 Share Posted December 5, 2020 Hi @silent, Your forced animation example is excellent, I was able to quickly set up a player controller. What I was unable to do is make the transition between animations smooth. I've tried using the following method, instead of SetLayerEnabled to add a blend weight as the docs state but it doesn't have any effect: playerMesh.SetLayer((int)AnimLayers.IDLE, false, 0.5f); playerMesh.SetLayer((int)AnimLayers.RUN_FORWARD, false, 0.5f); Any idea what we may be missing here? Link to comment
honya Posted December 6, 2020 Share Posted December 6, 2020 For blending between 2 animation use this function: playerMesh.LerpLayer(0, (int)AnimLayers.IDLE, (int)AnimLayers.RUN_FORWARD, weight); Link to comment
astressence Posted December 6, 2020 Share Posted December 6, 2020 Many thanks @honya, works like a charm. Link to comment
Recommended Posts