Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

FPSController rarely and unintentionally "teleports" large distances instantaneously

Discussion in 'Physics' started by TheChuckster, Oct 15, 2015.

  1. TheChuckster

    TheChuckster

    Joined:
    Dec 16, 2014
    Posts:
    28
    I am using a stock FPSController prefab as the first person player in my game, and sometimes my users "teleport" (as in change position by a large delta between frames) by a large distance that is well outside the level boundaries. This is of course, completely unintentional.

    My game has a very relaxed discovery-based aesthetic so I wanted slower mechanics similar to the older Unity first person controller prefab (as opposed to the default twitchy, "action" Duke Nukem-style character mechanics), so I have adjusted the following settings:

    Walk Speed to 2.5
    Run Speed to 7.5
    Runstep Lenghten [sic] 0
    Jump Speed 0 (no jumping)
    No Fov Kick
    No Head Bob
    No Jump Bob
    Step Interval 0 (no footsteps)

    As a bandaid, I set the rigid body collision to Continuous Dynamic (previously, it was discrete -- the default) -- since maybe a framerate drop on a slower computer might be causing a large delta t to accumulate in the position?

    My level has static walls with colliders attached to them so that this _should_ cause the character to bump into the wall instead of going through it whenever there is an extremely large delta x over delta t.

    Are there any other suggestions? Is there a way to govern the max velocity of a Character Controller other than tracking position changes manually and constraining them in, say, LateUpdate()?

    I wasn't able to dig up anybody in the past having this same issue.
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi there,

    Collision of your character; You say you use stock FPSController. Do you mean by that Standard assets for Unity 5 RigidBodyFPSController or something else? You say *max velocity of a Character Controller*, but Unity default FPS character uses Rigidbody and Capsule Collider.

    As far as I know Character Controller component shouldn't be mixed with rigidbody, either use CC and bake your own movement or use Rigidbody+Capsule Collider. I haven't used CC much at all so someone who actually knows it might be able to tell better. But I guess you are using Standard assets RigidBodyFPSController.

    It's pretty hard to say what might be a problem, I don't see image of level you use, what kind of colliders there are, what is the layout and how colliders overlap and so on. It could be many things causing this IMO.

    "extremely large delta" - based on my limited experience with physics, setting rigidbody collisionDetectionMode to CCD, does not guarantee that you won't go through walls, was testing this just a while ago. But I bet you are not moving like bullet if your game is in slow moving genre.

    "max velocity" - It's possible to modify velocity or Rigidbody, there are many tutorials and posts here where that is discussed.
     
  3. TheChuckster

    TheChuckster

    Joined:
    Dec 16, 2014
    Posts:
    28
    "Unity default FPS character uses Rigidbody and Capsule Collider."

    If I'm not mistaken, that seems to be inaccurate:


    As you can see from the screenshot, I am using stock FPSController found in "Standard Assets/Characters/FirstPersonCharacter/Prefabs/FPSController". The stock prefab includes both a CharacterController and a Rigidbody component attached to it, but not a Capsule Collider.

    It is my understanding that the CharacterController performs collision detection using an implicit capsule "collider" instead of explicitly attaching a collider as a component, and it does not use a force-based model for rigid body dynamics (instead, using first-order kinematics); whereas the RigidBodyFPSController performs collision detection using a Capsule Collider component and uses a force-based model for character motion and collision response (like you said).

    Maybe you thought I was using RigidBodyFPSController?

    "As far as I know Character Controller component shouldn't be mixed with rigidbody"

    I can see your reasoning as they do seem to mix two different approaches to physics simulation in games -- kinematics and dynamics, but I'm less inclined to believe that this is the problem, given that a stock prefab provided by Unity themselves mixes those components.

    "But I guess you are using Standard assets RigidBodyFPSController."

    No.

    "It's pretty hard to say what might be a problem, I don't see image of level you use, what kind of colliders there are, what is the layout and how colliders overlap and so on. It could be many things causing this IMO."

    It's a fairly standard static room that can be found on the asset store here.

    "It's possible to modify velocity or Rigidbody, there are many tutorials and posts here where that is discussed."

    Right, but I believe I asked about a CharacterController?

    I haven't seen any issues since changing Collision Detection in the Rigidbody component to Continuous Dynamic, but this was a rare issue to begin with, so I'm not 100% confident that it has been resolved.
     
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    TheChuckster:

    OK you know these asset files a lot more thoroughly than I - to be accurate, I haven't used Standard assets at all, only opened them a few times, so I wasn't aware exactly what file "FPSController" you mentioned was exactly, that's why I asked are you using "RigidBodyFPSController". Now I checked them again - seems like there are actually multiple FPS setups (like you mentioned):

    Standard Assets\Characters\FirstPersonCharacter\Prefabs\FPSController:
    FirstPersonController.cs + Character Controller + RB

    Standard Assets\Characters\FirstPersonCharacter\Prefabs\RigidBodyFPSController:
    RigidbodyFirstPersonController.cs + Capsule Collider + RB

    But in sample scenes there is only one type of demo I think (the one I picked):
    SampleScenes\Scenes\CharacterFirstPerson scene, containing RigidBodyFPSController:
    RigidbodyFirstPersonController.cs + RB + Capsule Collider

    A slight mix up, so we both wasted time answering nothing to each other! I only opened the scenes, didn't start browsing all the folders for asset, since I haven't used Standard assets that much. So yes - I thought you were using RigidBodyFPSController :)


    "CharacterController performs collision detection using an implicit capsule "collider""

    Yes it's derived from Collider class itself as far as I know.

    "I'm less inclined to believe that this is the problem, given that a stock prefab provided by Unity themselves mixes those components." (Character Controller + RB)
    Yes - It shouldn't be problem if RB is marked as kinematic but I wasn't aware of that above mentioned asset :). Now that I opened it, it shows it's set as kinematic, which should be OK - IMO.
    However if it was just typical Rigidbody under control of Physics system, and you move it using velocity, that might be not a good idea to have those two at the same time, as far as I know Character Controller and Rigidbody Physics movement won't mix well.

    "It's a fairly standard static room that can be found on the asset store here."
    It would be easier if everyone could see the asset, even better if there was some particular area where it happens, it might be just badly created content - or something else. But I understand if you can't share the asset image.

    "Right, but I believe I asked about a CharacterController?" (velocity)
    It's possible to modify velocity of Character Controller too, I've used character controller only few times but you can move using CharacterController.Move() - that way you can clamp the length of vector (movement speed) you use for move in that frame, very much like with Rigidbody.

    "I haven't seen any issues since changing Collision Detection in the Rigidbody component to Continuous Dynamic" (Continuous Collision Dynamic setting)

    I'm pretty unsure of this (= not tested) but I think this only works with non-kinematic Rigidbodies - I think it only has an effect on non-kinematic Rigidbodies. If someone else can verify this? And FPSController is marked kinematic.
    And moving fast enough will send you through walls either way. You have to use raycasting or similar alternatives to predict walls, I don't think you can use that fast Fixed Timestep that it wouldn't happen, but like I said, it could be something else as you are moving using slow speed.