Forum rules - please read before posting.

Player moves on Z axis on direction change

Hi Chris,

I'm making a game with direct control and want to move the player only on x axis (like a platformer).
I disabled UP and DOWN movement OnStart and everything looks fine.
My big problem is that when I turn the player from left to right (or opossite) the player slightly moves on z axis on each change of direction, I guess due to the turn animation. I want to keep the player striclty on the X axis.
The contraints on the Rigidbody component doesnt seem to do anything.

Any ideas? 

Comments

  • Are you using Unity's Root motion feature for your animations?  Try unchecking "Turn before walking" in the Player Inspector - that should help the character to face the right direction before moving.

    The Rigidbody constraints won't change anything, but as a last resort you could place colliders around the player to contain him within the Z-plane.
  • Yes, root motion. "Turn before walking" is unchecked but no effect at all.
    I'm using "Slow movement near collider" so placing colliders around the player affects it's movement when the player will get close to the side colliders.

    What I'm temporarily doing is to increase "turn speed" up to 1.000. This way the player turns instantly, but I'm loosing the turning animation which is cool.

    If you think of something I'd love to hear it! Thanks! 

  • The "Slow movement near collider" option should only be affected by colliders on a given layer.  Placing these side-colliders on a separate layer should mean they have no effect on that.
  • Yes! 
    Putting the colliders on their own layer will do the work.
    Thank you! 
  • Hi Chris,

    I use the "Player" component on a wheelchair and I have a decent controll of it (looks a bit like TinPot but with 4 wheels).
    My problem is that that it freezes the rotation on all axis on play and when I move the wheelchair on uphill or downhill the collider doesn't match the terrain angle (as a car would do).

    As you can see below, the back wheels do not touch the ground as the box collider cannot rotate and match the terrain.

    Any ideas on how to fix this?
    I use direct controls if you need this info.

    image
  • Please try to post separate issues in separate threads in future, as it makes it easier for others searching for similar questions.

    AC's freezing of the Rigidbody rotation can be disabled by removing line 1007 in Char.cs (in the latest release):

    _rigidbody.constraints = RigidbodyConstraints.FreezeRotation;

    If you can get good results controlling it yourself, I'll consider making it optional.  However, it may be that a custom script is necessary to get the best results.  Raycasting the floor to work out the orientation, and then rotating the mesh as a child object, would give you better control over it - allowing you to prevent sudden changes etc.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.