Search Unity

[Released] Kinematic Character Controller

Discussion in 'Assets and Asset Store' started by PhilSA, Sep 29, 2017.

  1. Rademanc

    Rademanc

    Joined:
    Feb 2, 2013
    Posts:
    11
    @PhilSA
    1: It was a new project.
    2. Windows 10
    3. Whatever the default is.
    4. 2017.2.0b2
    5. Yes it does look like the same issue.

    I ran it with 2017.2.0f3 with auto sync on and a timestep of 0.2 without any issues.

    Thanks for the support :)

    I am really happy with the controller.
    The reference implementation is quite good enough for what I have in mind too. ;)
     
  2. Discord

    Discord

    Joined:
    Mar 19, 2009
    Posts:
    1,008
    Any chance this works with Unity 5.6?
     
  3. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    The short answer is no,

    This package makes good use of Physics.ComputePenetration(), which was introduced in 5.6, but was buggy. It was later fixed in 2017.1, which is why that version is the minimum requirement.

    However, it's possible that it would work just fine with the latest 5.6 patch. I'll make some tests tonight and report back
     
    Discord likes this.
  4. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    @Discord
    Just tried it with Unity 5.6.3p4, and it works fine. I'm assuming the patch releases after that one will be fine too.

    The only thing to note is that one of the "Walkthrough" example scenes uses the Playables API for something that's unrelated to the character controller (I used it for moving a platform with an animation clip). It'll give you an error since it was introduced in 2017.1. Simply commenting out the code will fix this
     
  5. Discord

    Discord

    Joined:
    Mar 19, 2009
    Posts:
    1,008
    Awesome, thanks!
     
  6. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    Hi- Just curious about this character controller pack.
    Does this allow forward, backward, and side movement while you are in the air? I'm currently using the built in Unity 3rd person character controller and it doesn't allow this. I know I can modify it but I'd rather use a prebuilt package like this if possible. Thanks!
     
  7. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    It does allow this. Here's an example with exaggerated air speed values:
    https://i.gyazo.com/e07b658a286bd3004ceb538fde2386c8.mp4

    You can also do that a little bit in the WebGL demo, but it's less noticeable
     
    thestrandedmoose likes this.
  8. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    So cool! I also just realized I had another question: Is there swimming (underwater) type controls you can configure as well? I've seen other underwater controllers on the app store but none so far as nice as yours
     
  9. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    There is an example for writing a swimming state, along with a tutorial that takes you through all the steps required to code this.

    It is pretty robust in terms of reliability and smoothness, but I'm not sure if it has enough features to really be used in most games without adding anything to it in code. Here's what it looks like:
    https://i.gyazo.com/53d12ccf02ec91aa2ec9eea075984078.mp4
     
    thestrandedmoose likes this.
  10. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    Hey so I downloaded and imported the assets into my project and tried to run the example playground but I am getting a ton of errors. Mostly stuff like "OrbitCamera does not contain a definition for 'SetFollowTransform' and no extension method 'setFollowTransform of type OrbitCamera could not be found. "
     
  11. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    This sounds like the kind of problem you'd be getting if you already had a class named "OrbitCamera" in your project, and the script that is using OrbitCamera (ExamplePlayer) is trying to use the wrong one.

    You could try the following things:
    • Go find the OrbitCamera class in this package and see if it does have the methods that are supposedly missing
    • Look for any other class named "OrbitCamera" in your project, and see if you can delete them, or maybe change their name without refactoring
     
  12. JustinLarrabee

    JustinLarrabee

    Joined:
    Feb 3, 2013
    Posts:
    13
    How's progress coming on a multiplayer prototype? I'm really interested in using this package in that scenario because compared to the other controllers out there you manage your state very, very cleanly and I am confident that proper lag compensation is actually possible without gross, half-broken hacks. :)
     
  13. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    It's coming along slowly, but surely.

    I must find a balance between time spent on support and time spent on development, but it's mostly been spent on support these days due to the big asset store sale and the sudden influx of questions.

    I'm not complaining at all, though. This is really helping me to root out important problems. Just yesterday, while helping a client, I discovered a problem that may very well affect networking. Turns out that moving an interpolated kinematic rigidbody with transform.position or rigidbody.position actually does a weird buggy interpolation, and does not teleport it directly like I thought it would. The real way to teleport it is like this:


    This is very important for reverting characters to previous states and re-simulating inputs in the context of a networked game.

    But yeah, I'm hoping to release it at some point in december. I'll probably have more time for this once the sale is over
     
    Last edited: Dec 1, 2017
    Shinyclef and Petethegoat like this.
  14. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    @PhilSA Found a strange bug. Character is unable to move to the 60 degrees slope when you running forward and strafe at the same time.
     
  15. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I was able to repro it. Thanks for pointing it out, I'll look into this
     
  16. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    I noticed your work here, and read the thread where you had requested the ComputePenetration feature .That thread really gave me confidence you know what you're doing, so I will give this a purchase and try it out.

    I noticed your web demo mouse controls don't really work in Chrome. Did you lock your mouse so that it's always centered? It seems to jump when the invisible mouse hits the edge of the player and wraps back around to the other side. Downloaded firefox to demo it properly. It seems like a really solid controller. Nice one.
     
  17. iLoveYourFace

    iLoveYourFace

    Joined:
    Aug 23, 2017
    Posts:
    1
    I noticed the exact same thing happens with Google's Poly model viewer. You'd think they'd have it figured out in their own browser. It's like a weird form of torture using it
     
  18. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    you're right, I must've forgotten to remove the mouse lock last time I updated it. I'll re-upload soon

    Edit: scratch that, I wasn't able to find a proper solution for Chrome (unlocked cursor stops affecting the game as soon as it reaches the borders of the screen). I think I'll have to stick to asking people to open it in Firefox
     
    Last edited: Dec 3, 2017
  19. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    *facepalm yeah that was it. Sorry- I'm really new to this

    I had another question too... Right now it seems like your character just automatically always orients to face towards where the camera is facing... giving it the impression it's always looking wherever the camera is looking, but what if I want the character to be able to turn and run facing camera etc (more like a joystick approach rather than WASD), or turn the direction of the keypress- so if I press "A" or "D" he turns right or left and heads that way. If I hit "S" he turns towards camera... Essentially my character meshes should rotate to face the directions of the keypress. I think this is how most controls work on console games. Do you have any suggestions how I can achieve that effect with this controller?
     
  20. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    The example controller comes with a way to set the "target rotation".
    I don't know if its already used in the example but the code contains it anyway.

    The "orientation sharpness" is a good starting point, just look where its used in visual studio, and then see where that target rotation gets set from. From there you can make your own character controller.

    Try going through the tutorial the package comes with, that should clear up that question (and many more) in great detail.
     
  21. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    In ExamplePlayer, there is a point where we call
    Code (CSharp):
    1. Character.SetInputs(cameraOrientedInput, OrbitCamera.PlanarDirection);
    this line basically says: "We're gonna move with cameraOrientedInput vector, and set our rotation direction to OrbitCamera.PlanarDirection"

    To accomplish what you want, you can simply do this instead:
    Code (CSharp):
    1. Character.SetInputs(cameraOrientedInput, cameraOrientedInput.normalized);
    This means your target direction to rotate to will be your move direction at all times
     
    thestrandedmoose likes this.
  22. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    Dude you are amazing! This is exactly what I was looking for- THANK YOU

    I tried to find this originally in the walkthrough but couldnt... maybe it would be good in the future to include this in an example scene because I'm sure I'm not the only person who is looking for this kind of controller. Or It might be good as a checkbox setting in the Example Player? Not sure

    Thanks again!
     
    faolad likes this.
  23. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I'll definitely find a way to make this more clear and integrated by default. A lot of people have asked me about this
     
    thestrandedmoose likes this.
  24. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    98
    I am moving a VR camera parent via a rigidbody in FixedUpdate(), but I get some hitches/stutters as I am moving through the scene. I don't have the issues when using Translate in Update(), but I need to detect collisions. I have tried many things within the physics system, but nothing with perfect results. Will your character controller give me back my smooth stutter-free movement?
     
  25. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    If you move the camera in FixedUpdate, it needs to be interpolated properly. For example you could make your camera an interpolated kinematic rigidbody, and move it with rigidbody.MovePosition. This will make interpolation work properly.

    If you want to be certain that interpolation is working well, you can set your fixedTimeStep to something really high like 0.3, and it'll become really obvious
     
  26. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    98
    Your asset supplies all that plus the all important collisions when using a kinematic rigidbody, correct?

    Do I understand the docs correctly, and I could also use rigidbody.velocity?
     
  27. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I might need to know a little more about your camera setup in order to answer properly. Is your camera a separate object, or is it a child of the character? And what makes the camera need to be a rigidbody?
     
    Last edited: Dec 9, 2017
  28. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    98
    The camera is a child of a root object (parent). The parent has a rigidbody, so it will collide/stop at walls, or when traveling vertically, to stop at ceilings and floors. If I didn't need to detect these objects I would use Translate, which does work.
     
  29. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I see,
    So yes, in that case you can set the rigidbody to interpolate and move it only with .velocity and .angularVelocity (doing any sort of transform.position or transform.rotation changes on the object with the rigidbody will break interpolation). This will make the interpolation work
     
    Last edited: Dec 9, 2017
  30. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Little dev update:

    I took a break from networking today in order to implement something else that has been highly requested: improved step handling.

    You will now be able to select between two methods of step handling:
    • "Simple": This is the old one. It's efficient on performance, but cannot go higher than the capsule radius, and has trouble with certain edge cases such as stepping over a cylinder
    • "Complex": This is the new one. It has no stepping height limit, and handles edge-cases much better. It comes with a slightly higher performance cost (the cost of a few CapsuleCasts and an OverlapCapsule), but that cost is only present while you are actively moving against obstructions such as walls or steep slopes, or standing on steps.
    Here's the new step-handling method in action, with a ridiculously high step height just to prove its versatility:
    https://i.gyazo.com/b175837ede311e7cf89acfcbd5fbf3ca.mp4

    I still need to test this more thoroughly before releasing it, and see about adding an option to not lose any horizontal speed while stepping, but you can probably look forward to this in the next update

    ...now back to networking!
     
    Last edited: Dec 11, 2017
    DougRichardson and cdfru472 like this.
  31. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    I successfully ported the code from my own controller, except its rotation part... Any advice on how to port this part of the code for use with the Kinematic Character Controller?
    Code (csharp):
    1. if (!Input.GetMouseButton(1))
    2.    transform.Rotate(0, Input.GetAxisRaw("Horizontal") * characterRotationSpeed * Time.deltaTime, 0);
    3. else if (cameraController.targetCharacterExist)
    4.    transform.Rotate(0, Input.GetAxisRaw("Mouse X") * cameraController.sensitivity * cameraController.rotationAcceleration, 0);
     
  32. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    To do an equivalent of the Rotate method, you can use quaternion multiplications. Multiplying a quaternion A by a quaternion B makes A rotate locally by B's rotation, so all you'd have to do is create a quaternion that represents your input rotation, and in UpdateRotation you multiply your currentRotation by that

    It should give you something like this:
    Code (CSharp):
    1. public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
    2. {
    3.       float rotationAngleFromInput = 0; // Your input code would set this value from anywhere you want
    4.  
    5.       // Rotates the character around its local Y axis by that angle
    6.       currentRotation = currentRotation * Quaternion.Euler(0, rotationAngleFromInput, 0);
    7.  }
     
  33. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    Thank you, it works perfectly. Your controller is absolutely awesome!
     
  34. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    Hey Phil, I'm getting a weird issue when I connect a PS4 controller to Unity to control the character.

    The Move controls on the left analog stick are working perfectly, but the "Look" controls with the right stick drift in weird directions even when I'm not touching the right stick at all.

    I dont think it's an issue with the PS4 controller because I've tried it with multiple controllers.. The mouse seems to work fine for looking though... Do you know how I could fix it to work with both the mouse and analog stick?

    On the bright side: the movement works great with a PS4 controller! :D
     
  35. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Inputs are handled in ExamplePlayer.cs, and the code that's there by default is very rudimentary:


    Not sure what causes that behaviour with PS4 controller, but by default, it's just supposed to work with keyboard + mouse. There are so many different ways that one might want to handle input, and so many 3rd party solutions, that I decided to lend that responsibility to the users.

    If you want to change it, you just have to build the "_lookInputVector" differently. This is a Vector3 where X represents horizontal look input, and Y represents vertical look input
     
    thestrandedmoose likes this.
  36. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    Yeah I figure it is probably happening because the input axis for a mouse will give float values relative to the screen while a game controller's joystick will always snap back to Input.GetAxisRaw("Mouse Y") = 0 and Input.GetAxisRaw("Mouse X") = 0. So as soon as I touch the right analog stick on a controller, it is gathering the mouseLookAxisUp and MouseLookAxis right values of the mouse position on screen and adding those values to the values from the joystick. So if my mouse cursor was perfectly aligned in the middle of the screen, I predict there will be no drifting on the look direction..

    Not sure how I'd remedy this but I might try a third party plugin like InControl... Hopefully it will negate any mouse input while using a PS4 controller and vice versa
     
  37. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    98
    I don't get smooth movement, stutters do show up. I setup a very simple scene (Unity cubes) and a constant velocity to move past them. I have a parent container that holds the VR camera. On the parent I added KinematicCharacterMotor, leaving everything at the defaults and I add my character controller to it, which has:
    Code (CSharp):
    1. public override void UpdateVelocity(ref Vector3 currentVelocity, float deltaTime)
    2. {
    3.     currentVelocity = Vector3.left * speed * deltaTime;
    4. }
    Am I missing something?
     
    Last edited: Dec 13, 2017
  38. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Your UpdateVelocity code is fine, and it couldn't be a problem either way. I arranged things so that no matter what you return as the "currentVelocity", the movement of the character will always be properly interpolated

    This problem's gotta have something to do with the way VR makes the camera move, and the fact that it probably doesn't like having a rigidbody attached to that camera. What's probably happening is that VR sets the camera's position/rotation directly, and this messes with your camera rigidbody's interpolation. The fact that you end up with a rigidbody within another rigidbody is also very suspicious (it's been known to cause all kinds of problems). Here's a few thoughts on this:
    • In Edit > Project Settings > Time, set the Fixed Timestep to 0.3. Now try playing your example scene.
      • Do you see your camera moving like a slideshow (does it update only about 3 times per second)?
      • And if you look at your character object in the scene view, is it still moving smoothly?
    • To avoid problems like these, I personally wouldn't use a rigidbody to handle collisions on the VR camera. Instead, I'd attach a script to the camera that does a Physics.OverlapSphereNonAlloc(), and then a Physics.ComputePenetration() to solve collisions manually. And all this would happen in LateUpdate(). Not only would this make your collision handling frame-perfect, but it's also likely to solve this jitteriness problem. Look at the example code here if you're not sure how this works
     
    Last edited: Dec 13, 2017
  39. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    98
    Thanks for the ideas.

    The camera does not have a rigidbody, and there is only one rigidbody.
    CameraParent (with rb and movement script) > Camera (child)

    Results with 0.3 Fixed Timestep:
    Note: When I reduced the Timestep, the rigidbody went very fast, until I reduced the speed multiplier. That means the velocity is affected by the Timestep and is not absolute, so if the Timestep varied a little, would that cause a hitch?
    - The CameraParent walks along like a slideshow (Scene view)
    - The Camera is mostly smooth (Scene view)
    - VR mostly smooth, some stutters as originally described

    Does the above give you any other ideas?

    I will look into your last recommendation. Thanks.
     
    Last edited: Dec 14, 2017
  40. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Just to make sure I understand, is your hierarchy like....
    • Character object (has the KinematicCharacterMotor)
    • CameraParent (has rigidbody, and follows the character object with a script)
      • Camera
    or is it like...
    • Character object (has the KinematicCharacterMotor)
      • Camera parent (has rigidbody)
        • Camera
    or like....
    • Camera parent (has the KinematicCharacterMotor (therefore, has a rigidbody))
      • Camera
    ?
     
  41. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    Hey Phil- quick question about the character controller... Is there an easy way to make it fly/hover?
    Say- when holding the space bar the character will float upwards instead of jump?

    I know theres a noClip state but thats not quite what I'm looking for. Thanks man!

    Edit: Actually I think I might be on track towards figuring it out... Will post here once I've got a solution

    Edit: OK I got it. Posting here for anyone else that wants to use flight in their character:

    Phil has done a really great job of making this super simple. Open MyPlayer or ExamplePlayer script (whichever youre using) and go to the Jump section:

    Right now it should say something like:
    if (Input.GetButtonDown ("Jump")) { Character.Jump (); }

    Just change it to:
    if (Input.GetButton ("Jump")) {
    Character.GetComponent<KinematicCharacterMotor>().ForceUnground ();
    Character.AddVelocity (Vector3.up * .6f);
    }

    You have to force unground for obvious reasons mentioned in the walkthrough- alternatively, if you want your character to launch off like a superhero or Overwatch character (COUGH*Pharah*COUGH) you can do this:

    if (Input.GetButton ("Jump")) {
    Character.Jump ();
    Character.AddVelocity (Vector3.up * .6f);
    }

    You can adjust .6f to whatever speed you desire
     
    Last edited: Dec 14, 2017
    apexsoftworks, davidseth8 and PhilSA like this.
  42. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    98
    The hierarchy is the one quoted above. The Camera parent also has the movement script, where velocity is set.
     
  43. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Oh wait, I was actually totally wrong in the other post when I said the velocity code wasn't a problem. I didn't notice the "* deltaTime". Unlike direct movements, velocities are independant of framerates, so they must not be multiplied by the deltaTime. This is what's causing your problem of the velocity being different depending on the fixedTimeStep.

    So if the CameraParent (aka the KinematicCharacterMotor) is a slideshow, this is not normal. The first thing we need to establish is if the VR camera setup has anything to do with that problem. Try fixing the velocity as described above, putting the fixedTimeStep back to 0.3, and running the default CharacterPlayground scene that comes with the package.

    If you still see the character moving like a slideshow under these conditions, that means something in the core scripts may have been altered
     
    Last edited: Dec 15, 2017
  44. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    @PhilSA Any advice how to suppress speed when the character jumps up the slopes?
     
    Last edited: Dec 17, 2017
  45. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    In the jump handling part of ExampleCharacterController's UpdateVelocity(), there's this code:


    I think what you want is to remove the whole " - Vector3.Project(....)" part, which tries to cancel-out slope velocity when jumping. If not, I might need some more clarifications
     
  46. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    Thank you, I figured it out.
     
  47. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    98
    Makes sense about the velocity, and it is consistent now. Since you supply deltaTime in the call I assumed it was suppose to be used.

    I was wrong about the CameraParent slideshowing. When it is selected in the Hierarchy, the transform gizmo in the scene view does step every 1/3 of a second, but the actual object is smooth. So, it is smooth as viewed from Scene view.

    Now I am getting mostly smooth results. Instead of regular jitter, a few really big hitches, so I did a build with the profiler and I am having no hitches right now. I will keep testing.

    Edit: I just rebuilt scene without devel/profile and it has big hitches, occurring every 3 to 20 seconds. I then built with profiler on and no hitches. Strange.

    Edit2: A development build (with or without profiling) = no hitches, non-devel build = hitches.

    Edit3: Ah, I the timestep was still at 0.3 on the above hitches. I switched it to 0.01111 and the big hitches are gone, but the occasional consistent jitters are back. This is in a deployment build.
     
    Last edited: Dec 16, 2017
  48. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    @flyingaudio
    Do you think it's possible that the jitter you're still experiencing might look like this bug ?

    Rigidbody intrepolation has some problems in Unity 2017.2 and .3, and it seems to depend a lot on the platforms/contexts. Sometimes it happens, sometimes it doesn't. However, @yant mentioned here that this might get fixed at some point in 2018.1 when PhysX3.4 arrives

    I'd suggest making some very simple tests, like replacing the character controller with an extremely simple interpolated kinematic rigidbody that moves with your input, and see if you still get jitter with that same camera setup. You could also try your current setup in 2017.1 to see if that solves the problem
     
    Last edited: Dec 16, 2017
  49. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    @flyingaudio

    So I just tried the above test in 2017.3.0f2. I started a completely new project, added an interpolated kinematic rigidbody cube to a scene, added a regular non-VR camera as a child, and started moving around with a simple script. And I do get jitters every 1 second or so in a build - but not in editor. This very clearly seems like an engine bug to me

    Here's the code I used to move my rigidbody around:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class InterpTest : MonoBehaviour
    6. {
    7.  
    8.     public Rigidbody Rigidbody;
    9.     public float MouseSensitivity = 2f;
    10.     public float Speed = 0.25f;
    11.  
    12.     private Vector3 _moveInputVector = Vector3.zero;
    13.     private Vector3 _lookInputVector = Vector3.zero;
    14.  
    15.     private void FixedUpdate()
    16.     {
    17.         float moveAxisForward = Input.GetAxisRaw("Vertical");
    18.         float moveAxisRight = Input.GetAxisRaw("Horizontal");
    19.         float mouseLookAxisUp = Input.GetAxisRaw("Mouse Y");
    20.         float mouseLookAxisRight = Input.GetAxisRaw("Mouse X");
    21.         _moveInputVector = new Vector3(moveAxisRight, 0f, moveAxisForward);
    22.         _moveInputVector = Vector3.ClampMagnitude(_moveInputVector, 1f);
    23.  
    24.         Quaternion rotationYFromInput = Quaternion.Euler(Vector3.up * mouseLookAxisRight * MouseSensitivity);
    25.         Quaternion rotationXFromInput = Quaternion.Euler(Vector3.left * mouseLookAxisUp * MouseSensitivity);
    26.         Rigidbody.MoveRotation(rotationYFromInput * Rigidbody.rotation * rotationXFromInput);
    27.  
    28.         Rigidbody.MovePosition(Rigidbody.position + (Rigidbody.rotation * _moveInputVector * Speed));
    29.     }
    30. }
    31.  
     
    Last edited: Dec 16, 2017
  50. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    This would be something you'd have to implement yourself, but it'd be quite simple. Here's an overview of what you'd have to do:
    1. When you press a certain button, or when you detect a collision with another character (depends on how you want to trigger attaching to characters)...
    2. Call an already-existing method on the jumping character controller that deactivates its movement/physics logic
    3. Either make your character a child of the other, or write some code on Update() that acts like a parent constraint and makes the character follow the other without having to use actual parenting
     
    Last edited: Dec 17, 2017