Forum rules - please read before posting.

Stop Movement near walls setup

RemRem
edited June 2016 in Technical Q&A
So I have been working with Sprites Unity Complex to make use of this Stop Movement Near Walls feature but the results aren't great... I put my box colliders in a new layer I made called Walls and set my character to detect this layer's colliders, and yet, even when she stops, there's this weird jerky movement... Like if the player's collider is bouncing off the wall collider.

I've uploaded the video to something called Sendvid (not YouTube since I don't want my "fans" to see this lol ;) ; also, please ignore the weird character switch in the beginning - it's still very much WIP at this point):



Question I wanna ask is this: how do I set up my character to make her stand still upon hitting a collider instead of... doing what she's doing in the vid ;) ? If needed I will provide screenshots of my player settings.

http://sendvid.com/p7hf0wn4

Comments

  • I should re-iterate that it's a slow movement feature, not stop completely.  There has to be some movement, however slight, otherwise the character will become unresponsive.

    There appear to be two issues here - the first is the "bouncing" effect, the second being the animation continuing to play.

    For the first, I'll need to see a shot of your Player's full Inspector.  For the second, you'll need to tweak your Animator window and Player Inspector such that the slowdown caused by nearby walls causes a Walk -> Idle transition.  It's a case of keeping an eye on the speed dip when nearing walls, and adjusting your transitions to suit.

    For the best results, you chould also look into creating a Blend tree for your Idle and Walk animations, so that the speed of the animation playback is synced with the "Move speed" float parameter.  This will allow the slowdown speed to be more gradual and natural - though I've only tested it myself in 3D.
  • RemRem
    edited June 2016
    Here's some shots of my player inspector:

    image

    image

    I've adjusted the walk -> idle transition so that it switches to walk when speed>0.8 (previously 0.1). Speed seems to go down to 0.65 upon hitting the wall collider. The idle anim plays okay but with the same twitchy movement. That bounciness really has to be removed somehow but I played with settings a lot and none of them seem to have any impact on that whatsoever...

    image

    I'm also trying to set up the blend tree but man, that thing is tough... ;) Here's what I got so far (was hoping to achieve animation slowdown to 0.01 between speed 0.6 and 0.8 but it's not really working):

    image
  • I've recreated the bouncy effect and will look to provide a fix in v1.52a.

    As for the blend tree, you're blending between 4 states that are all the same - it should be a simple blend between Idle and Walk (then 3 others for all directions in separate Blend trees).  It's an easier process to grasp in 3D, you may want to look at some Unity tutorials before tackling it.
  • RemRem
    edited December 2016
    For anyone else working on a 2D direct control game like mine, searching this forum for help with this particular problem, here's a very useful method of stopping the Sprites Unity animated character without collision cubes:

    -use a trigger instead, set it to (player:constrain {disable left or right} ) for on enter, and again, on exit (player:constrain {enable left or right} ). In my game for some reason it's reverted - if I want to stop player walking further right I have to constrain left... but I guess it's something I messed up at some point long time ago. Just experiment with this. It's super quick and makes player stop walking in place, and going straight to idle upon hitting that trigger! ;) Just stick the trigger where the wall's supposed to be and voila! ;)


  • Hello Rem and Chris,
    I'm also using Rem's method with triggers, since I don't like the jerky, bouncy movements the character makes when stopping at a collider.

    My first note is that I can't use both an enter and an exit on the same trigger, but I solved this easily by setting a second trigger adjacent to the first, which enables the movement again.

    Second, I also need to reverse the directions, just as Rem, although I don't understand why.

    So far so good, and when I try this myself, it works well. However, two testers have now reported that the character gets stuck because the the constraints don't work as expected. One player even reported that the constraints persisted through a save game, and even upon restarting the game, which sounds super weird in my ears.

    I can't reproduce this error myself. When I try the scene in questions, the characters stops and regains controls just fine.

    Is there anything about the constraints that's dependent on some kind of hardware setting, or something that makes it different on different machines?

    Are there now better ways of making a character stop?

  • Best to take it from the top in terms of describing the issue. What's your movement method, and what is the fundamental issue you're facing?

    Generally speaking, "jerky" or "bouncy" motion can be eliminated by attaching a Rigidbody 2D component to the character, enabling Interpolation, and checking Move with Rigidbody? in the Player's Inspector.

  • But will that make the character stop moving? I don't want my character to treadmill-walk against an obstacle, because that looks strange and unrealistic. I want the animation to cease.

    So Rem's solution works perfectly for me because the character stops moving as well as animating.

    However, some testers now reported that the character gets stuck because, I assume, the constraints don't enable/disable as they should (a problem I can't recreate now matter how hard I try). So I just wondered if this was an unreliable way to do it.

  • edited November 2022

    By "stop moving", you're referring to animation - not the physical movement of the character?

    The Slow movement near walls? feature should allow for this - but as I mention above it will only slow movement as opposed to stop it completely.

    If you alter your Idle <-> Walk threshold values to account for this, however, you should be able to prevent the character from playing their walk animation.

    I wouldn't say using constraints on walls is the best way. If need be, a script to prevent walk animations from playing when facing walls could be incorporated - but physically preventing movement sholuld be avoided.

  • Thank you. How do I tweak the Idle<->Walk threshold value?

  • Just popping back in to say that I found what caused the error for me:
    In some cases, a hotspot could be interacted with while the character was standing on one of the triggers that constrained movement. If the character was then forced to move to a certain point, the constraints would persist.
    The solution was simply to make sure no hotspot is close enough to a movement trigger to allow for that kind of overlap. I know you don't recommend this solution, but for the time being it's completely unproblematic for me...

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.