Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to match player speed variable to character controller move?

Discussion in 'Editor & General Support' started by Zebbi, Jul 13, 2019.

  1. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I'm using character controller for the player movement, and a speed variable is used to control how fast the player moves, accelerates and decelerates. This is then passed into the vector3 that drives the character controller Move() function. The problem is, when the character controller is against a wall and stops, the speed variable still thinks the player is moving. I'm not sure how to correct this, what's the usual method of working with character controller in this way?
     
  2. ibbybn

    ibbybn

    Joined:
    Jan 6, 2017
    Posts:
    193
    Just check in Move() with a raycast if the player can move forward otherwise do another animation?
     
  3. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Thanks, but I don't mean the animation, I mean the variable that sets the speed that controls the vector3 that drives the Move() function.
     
  4. ibbybn

    ibbybn

    Joined:
    Jan 6, 2017
    Posts:
    193
    Well then instead of the animation change the speed to 0 when a raycast hits under a certain distance? I don't use the character controller but that's pretty much how all of them check for walls.. Maybe I'm misunderstanding, you don't know how to change the speed variable?
     
    Last edited: Jul 13, 2019
  5. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Yeah, I was just hoping there was a way of feeding the character controller's internal velocity back to mine so it knows if it's hit a wall by itself, either that or maybe setting character controller's velocity manually?