Search Unity

  1. Unity 2019.2 is now released.
    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:
    197
    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:
    133
    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:
    197
    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:
    133
    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:
    197
    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?