- Home /
After played an animation how to update character position?
Hi all, I am quite new for Unity and my game is a 3rd person view game. My controller is PlayerRelativeControl in Unity, after my character collide a collider it will play a wallrun animation, but the wallrun animation will be loop even I have changed it to once in wrap mode, also, the character position cannot be updated which is supposed on the destination after wallrun. Below is my code:
var canAnimate:boolean = false;
var animationTarget : Animation;
function OnTriggerEnter(coll:Collider){
canAnimate = true;
}
function OnTriggerExit(coll:Collider){
canAnimate = false;
}
function Update(){
if(canAnimate){
animationTarget.Play("wallrun");
}
Thanks in advance for any kindly advice ;)
I wish this was made clearer for new users, so just some tips on using this 'site (for ALL new users) :
How to accept an answer :
On the left-hand-side of the Answer box , there are the following icons :
: Thumb Up : Number (of votes) : Thumb Down : A Tick :
If an answer worked for you , click on the 'Tick' , it should now be highlighted in green. If you like an answer on Any question , you can click on the Thumb UP , it should now be highlighted in green , and the number of votes should rise by 1.
How to reply to an answer / post a comment :
To make a comment , USE the 'add new comment' button, a window then opens to type in. The answer fields are for ANSWERS, so unless you are answering your own question , DON'T write in an answer box. This helps the 'site work properly, especially when other people are searching for answers, and want to read answers , not comments.
IF your question changes slightly while commenting and reading comments , EDIT the original Question, so anyone reading from the beginning knows what you are asking.
This will make for a happy experience for everyone. I made mistakes starting on this 'site too, but everyone is helpful if you learn and change these habits.
Following these simple steps helps the website work , and other readers to find answers also.
Happy Coding =]
the FAQ appears at the top of the page : http://answers.unity3d.com/page/faq.html
also : http://answers.unity3d.com/questions/133869/how-to-ask-a-good-question.html
no worries , just a friendly FYI (it's been happening alot , nothing personal) =]
As I said in my comment to an answer I am really interested in this, having only just last night finishing the 3D Buzz TPC tutorial. I can't wait to add some more '$$anonymous$$b Raider' 'PoP' functionality.
Hope you get your answer, Happy Coding =]
Thanks for the code you suggested, but I need time to digest for my coding level, nice to have you guys help here~
In the tutorial : Section 4 - Integrating Animated $$anonymous$$aya Characters
review the video : 27 - Climbing Implementation
also : 25 - Climbing $$anonymous$$essage Flow (but this can seem confusing)
Edit :
What is happening is : (Person is refering to the $$anonymous$$odel, Character Controller refers to the green mesh capsule collider)
when you hit climb, an animation takes over. This animation moves away from the normal Person's Local position (i.e. the Person moves up the local Y-axis). After the animation , the Character Controller (green mesh capsule) is at position (0, 0, 0) BUT the Person's feet are at (0, 2.8, 0).
So the part that is to do with pelvis, the code finds where the Person's pelvis is , then $$anonymous$$oves the Character Controller back to that, so the Character cController is in line with the Person's feet again.
this is the trick. if your wall-run is an animation that moves the Person's position away from (0, 0, 0), then after the animation you have to move the Character Controller to where the Person is now.
Watch the video '27 - Climbing Implementation' while thinking about this.
Answer by JayMHelpsU · Apr 12, 2012 at 07:23 AM
var canAnimate:boolean = false; var animationTarget : Animation; var PlayerPos : Vector3
function OnTriggerEnter(coll:Collider){ canAnimate = true; }
function OnTriggerExit(coll:Collider){ canAnimate = false; }
function Update(){ if(canAnimate) { animationTarget.Play("wallrun"); } else if (animationTarget.IsPlaying) { PlayerPos = animationTarget.transform.position; } } Hope this works, if not please tell me :)
Answer by JayMHelpsU · Apr 12, 2012 at 07:23 AM
Sorry Edit to before this is the real code SORRY :)
var canAnimate:boolean = false; var animationTarget : Animation; var playerpos : Vector3;
function OnTriggerEnter(coll:Collider){ canAnimate = true; }
function OnTriggerExit(coll:Collider){ canAnimate = false; }
function Update(){ if(canAnimate){ animationTarget.Play("wallrun"); } if animationTarget.IsPlaying("wallrun"); { else playerpos = gameObject.transform.position; } }
Thanks for your kindly help and your code inspires me :) However seems the code is not complete, I suspect there should have some codes missed:
if animationTarget.IsPlaying("wallrun");
// some codes should be here
}else{ playerpos = gameObject.transform.position;
Besides, I found 3dbuzz climbing system is quite similar with my idea, it will set a climbing point where the animation start and clear the climbing point after animation done.
http://www.3dbuzz.com/vbforum/sv_showvideo.php?v=4950
Please advice whether i can do this or any solution, thanks :)
with the 3D Buzz tutorial , the Important part after the climb is when the character controller is moved to the Player $$anonymous$$odel . So you need to find the pelvis of your animation , then move the character controller back to it's correct position in relation to the pelvis , After the climbing animation has finished. e.g.
in the Awake method :
pelvis = transform.FindChild("Body") as Transform; // $$anonymous$$Y label
and in the climbing method :
}
else
{
$$anonymous$$yState = CharacterState.Idle;
animation.Play("TPCperson1_Idle");
var postClimbOffset = transform.TransformDirection(PostClimbOffset);
transform.position = Vector3(pelvis.position.x,
climbPoint.position.y + climbPoint.localScale.y / 2,
pelvis.position.z) + postClimbOffset;
// OR .. pelvis.transform.position = transform.position; // nope
pelvis.transform.position = new Vector3(transform.position.x,
//transform.position.y + (pelvis.localScale.y / 2), // 3D buzz char ctrlr position
transform.position.y + (pelvis.localScale.y * 3), // my position
transform.position.z);
}
don't forget the conditional checks, as in the method climb =]
I am interested in this too for using ledges , I hadn't thought of PoP-style wall-run. Hope you get it =]
Thanks @alucardj , But , in 3DBuzz tutorial of wall climbing they didn't update the pelvis position . Why is that ????
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Play animation once 1 Answer
Play animation for horizontal and vertical movement? 1 Answer
Mixamo Call Animation from Script 0 Answers
Adding animation clips via script 2 Answers