#I have a movement script attached to my

1 messages · Page 1 of 1 (latest)

modest flicker
#

Attached screenshot for hierarchy + inspector:

uneven geyser
#

Thanks

modest flicker
#

Thanks for suggesting that, didn't realize they were enabled here

uneven geyser
#

So the TL;DR is that you expect the object to move, but it doesn't, the transform stays 0,0,0, correct?

uneven geyser
modest flicker
#

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

uneven geyser
#

Ah right

#

Hm

#

If you go out further, does it still not move?

modest flicker
#

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

uneven geyser
#

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

modest flicker
#

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

uneven geyser
#

Take your time

modest flicker
#

yep, the capsule thing goes away when I remove the controller

uneven geyser
#

Could you provide me with the whole code?

#

Every script that is on the player

#

Just need to make sure nothing conflicts with it

modest flicker
#

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

uneven geyser
#

The other as well, please

uneven geyser
modest flicker
#
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;
  }
}
modest flicker
uneven geyser
#

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

modest flicker
#

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

uneven geyser
#

I mean it's kinda preference so fair enough

modest flicker
#

yeah, I agree with your point still

#

there's times when I'd avoid it

uneven geyser
#

The fun part is that you do explicitely state private heh

#

Which arguably is less important that explicitly stating the Type

modest flicker
#

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

uneven geyser
#

Yeah fair enough

modest flicker
#

My main line of work is in Typescript, where things tend to be a tad different sometimes

uneven geyser
uneven geyser
#

Oh by the way, do you've any errors?

modest flicker
#

nope, nothing at all

uneven geyser
#

Peculiar

#

It might have to do with the animation

#

Could you try to decouple it from the animation to test?

modest flicker
#

in what way? You mean just test if changing the transform would move it as expected?

uneven geyser
#

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

modest flicker
#

kk, let's see

uneven geyser
#

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

modest flicker
#

would you look at that

uneven geyser
#

Wait that was it?

modest flicker
#

when it runs in an update, the collider follows

#
controller.Move(Vector3.forward * Time.deltaTime);
uneven geyser
#

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

modest flicker
#

I now need to learn what the science behind this is

uneven geyser
#

But I bet you'd know that given you have 10+ years experience 😅

uneven geyser
modest flicker
uneven geyser
#

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

modest flicker
#

that could work, but I feel like that's slightly cheating

uneven geyser
#

Yes

modest flicker
#

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

uneven geyser
#

But I can provide you with no other solution other than just yeeting the CharacterController and using a RigidBody and EllipseColliderCapsuleCollider

modest flicker
#

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?

uneven geyser
#

It has it's own Physics

modest flicker
#

oh, I see!

uneven geyser
#

Don't combine an RB and a CharacterController btw

modest flicker
#

will remember that!

#

nice, time to dig more into docs then

#

it's quite a new world for me, for now

uneven geyser
#

Remembered it wrong

uneven geyser
#

Is this your own project or some kind of tutorial?

modest flicker
#

my own, this is usually how I learn most effectively. Ie. solving my own problems by supplementing with topic-specific tuts/papers/writeups

uneven geyser
#

That's fair, but I'd still highly recommend checking out Unity Learn

modest flicker
#

I'll take a look into it, thanks for suggesting!

#

I'll close the thread, since I guess we're solved here

#

thx again!