#I have a movement script attached to my
1 messages · Page 1 of 1 (latest)
Thanks
Thanks for suggesting that, didn't realize they were enabled here
So the TL;DR is that you expect the object to move, but it doesn't, the transform stays 0,0,0, correct?
It isn't always necessary, but if it gets burried it can be nice to create a thread for it
the player moves when I play the game, as I'd expect him to. I actually moved it in the screenshot by just walking forwards on my gamepad, but you can see the transform is still at 0,0,0 and that the capsule wireframe (that I believe comes from the animator?) hasn't moved with it
nop. I can go any direction, all around the scene
it will always stay at 0,0,0
there is no scripts attached to anything else that'd restrict its' movement
there is only one movement script on the player, which I've showed relevant parts of above. I can give you the whole thing if you'd like, but it's just some calculations that arrive at the values that are set
I don't use CharacterControllers, but I believe the collider is bound to that and created by the Component, right?
So if you remove the CharacterController Component then the collider disappears too
I presume so - I don't actually know as I'm extremely new to this
lemme test this
gimme a sec to re-launch unity
Take your time
yep, the capsule thing goes away when I remove the controller
Could you provide me with the whole code?
Every script that is on the player
Just need to make sure nothing conflicts with it
yepyep
public class ThirdPersonMovement : MonoBehaviour {
public CharacterController controller;
public Animator animator;
private static readonly int InputX = Animator.StringToHash("InputX");
private static readonly int InputY = Animator.StringToHash("InputY");
private void Update() {
var horizontalInput = Input.GetAxisRaw("Horizontal");
var verticalInput = Input.GetAxisRaw("Vertical");
var movementDirection = new Vector3(horizontalInput, 0f, verticalInput);
animator.SetFloat(InputX, movementDirection.x, 0.05f, Time.deltaTime);
animator.SetFloat(InputY, movementDirection.z, 0.05f, Time.deltaTime);
}
private void OnAnimatorMove() {
var velocity = animator.deltaPosition;
controller.Move(velocity);
}
}
as simple as that
The other as well, please
By the way, I'd not excessively use var
public class ThirdPersonCamera : MonoBehaviour {
public Transform player;
public new Transform camera;
public float rotationSpeed = 0.0f;
private void Update() {
var targetRotation = Quaternion.Euler(player.eulerAngles.x, camera.eulerAngles.y, player.eulerAngles.z);
player.rotation = Quaternion.Slerp(player.rotation, targetRotation, rotationSpeed);
rotationSpeed += Time.deltaTime;
}
}
how so?
It makes code harder to read
If something has a very difficult return type, then use var
But if it's just a Vector3, just use that honestly
oh, I have 10+ years of professional exp under my belt, I'm aware of when to and when not to utilize it and how to make it readable :D
I just don't do gamedev specifically ;P
I mean it's kinda preference so fair enough
The fun part is that you do explicitely state private heh
Which arguably is less important that explicitly stating the Type
hahaha fair, I have to admit I've been doing that for ages
It's just a bunch of code-style things I don't really even think of on the daily and just roll with what I usually do :P
Yeah fair enough
My main line of work is in Typescript, where things tend to be a tad different sometimes
I do as well, btw, I was just pointing it out
Fair yeah
Oh by the way, do you've any errors?
nope, nothing at all
Peculiar
It might have to do with the animation
Could you try to decouple it from the animation to test?
in what way? You mean just test if changing the transform would move it as expected?
Like just putting the movement in an update or fixedupdate whater so that it's not reliant on animation
Give it a static speed or smth
kk, let's see
I'm not convinced it's the problem, but it's good to rule it out
Cuz honestly I'm kinda stumped why it just leaves the poor collider behind
Wait that was it?
when it runs in an update, the collider follows
controller.Move(Vector3.forward * Time.deltaTime);
I'm a genius apparently lmao
This is why it's good to rule things out even when you think that really isn't the issue lol
I now need to learn what the science behind this is
But I bet you'd know that given you have 10+ years experience 😅
Good question
hahaha got me here lol
Well I guess you can patch it with a boolean maybe?
Have a boolean in the OnAnimatorMove, and then it in update to check for the bool
If that's necessary
that could work, but I feel like that's slightly cheating
Yes
I need to learn/figure out why/how does the OnAnimatorMove not allow for the transform updates
then go from there
thank you for your help though, and I'll hit you up with what I find
But I can provide you with no other solution other than just yeeting the CharacterController and using a RigidBody and EllipseColliderCapsuleCollider
Given that I will not have (m)any physical interactions (for now, at least), is using a rigidbody here sensible?
or does it not matter much?
Your CharacterContoller does the same
It has it's own Physics
oh, I see!
Don't combine an RB and a CharacterController btw
will remember that!
nice, time to dig more into docs then
it's quite a new world for me, for now
I meant CapsuleCollider btw
Remembered it wrong
Maybe do a Unity Learn
Is this your own project or some kind of tutorial?
my own, this is usually how I learn most effectively. Ie. solving my own problems by supplementing with topic-specific tuts/papers/writeups
That's fair, but I'd still highly recommend checking out Unity Learn