Hey Everyone,
I am new to unity and I created basic movements of character with character controller (Run,walk,jump) but when I am trying to move controller for climbing high obstacles (Like hanging on ledge ) ,with animation clips curves , a
controller.center=(new Vector3(0,animator.GetFloat(“ColliderY”),0.0f));
Its not working, values of controller in inspector is changing but not moving.
I also tried controller.Move() but it is jumping higher and animation is happening above the obstacle xD.
And also I am using Starter Assets-Third Person Controller
Root Animation worked somewhat but I read somewhere that it’s not good for game mechanics.
How about using some Debug.Log lines to print the values of some suspected variables involved in moving the player, to find out whats going on?
For example does animator.GetFloat(“ColliderY”) returns the values you are expecting. And is the gravity really disabled for the rigidbody as you think? And so on.
I used the debug log and it turned out that float gravity was not being modified, now its moving but I have to make the ColliderY values more accurate. Is there another way of doing this without curves?
Thank you so much for your help
Just an fyi for efficiencies sake unless there’s a specific reason to use OnTriggerStay, OnTriggerEnter/Exit works just fine for most collision, stay is called every frame so I’d avoid that.
Are you talking about changing animations in general? You may want to be a bit more specific, in terms of changing generally what I like to do is make use of setBool/SetTrigger for animations and then you can use transitions to smooth everything out. Your method looks a little weird to me so I wonder what sort of tutorial you’re following, nothing wrong with floats though but I tend to prefer the other method because I feel like it gives me more control, there are multiple ways to do animations and you’ve got to find what fits your requirements best.
I know how to change animations but I want to make my character climb and animation is moving from its origin, so when I apply it to my character , the controller stays in its place but body moves and comes back to the controller. I tried controller.Move() and controller.center but results are bad.
In that case that sounds like an issue with your hierarchy setup maybe more than the code? What I like to do is use an empty to handle all of my movement and pivot centre behaviour. This might sound strange, but it means you can do everything accurately and you don’t have to worry about any extra components elsewhere mucking up any movement or code you’re trying to do, if you want to access the components within that empty then use GetComponentInChildren. Let me know if that helps any with the behaviour. So to simplify it a bit I have everything go descending from a kind of ‘master’ empty at the top of the hierarchy to prevent that kind of weirdness with complicated prefabs. I also feel like this is more organised in the long run but other people will have opinions on that.
There should be nothing wrong with it as it seems to be fairly common practice in Unity, you’ve just messed up the setup somewhere and need to go through it.