- Home /
add constant z axis movement to third person / character controller
is there any way I can add a continuous forward movement to a third person character? The game is a snowboard game so I only want it to move / rotate left and right. I have tried using a ridged body instead but am having uber problems getting it to work how I want
Thanks!! :)
Answer by stefano001 · Jul 17, 2010 at 03:28 AM
You can try with a simple animation-driven character controller like the one released for Unity by Mixamo. It is powered by a RootMotionComputer script, created by Adam Mechtley. It allows the controller to use actual animation curves to drive the motion of the root of the character, instead of using a procedural approach which would lead in general to a worse quality and motion artifacts like foot slide. On top of that you can add a constant Z-foward speed on the parent game object on the Update() function. Done. Hope this helps!
You can download the project file, as well as see video tutorials about its use here:
Cheers!
Stefano
Answer by burtonposey · Feb 07, 2010 at 05:08 AM
Have you taken a look at ConstantForce? http://unity3d.com/support/documentation/ScriptReference/ConstantForce.html . It provides relative and absolute force (and torque) and remains in effect until you apply a different force to the rigidbody.
Yes, that doesn't really work either as once the character turns a corner it flies off the track, even if the force is applied locally. Not getting very far with this.. :s
O$$anonymous$$ so am now getting somewhere with relative force and drag - thanks :)
Answer by Ashkan_gc · Feb 05, 2010 at 05:56 PM
i think you can use wheel colliders for this. if you want to constantly move something you should call Transform.Translate or CharacterController.Move in Update.
Answer by lokstok · Feb 05, 2010 at 06:10 PM
Here's something I had tried out sometime back for something similar..
public float movingRate = 0.1f; //rate of movement
private float mLeftRightInput; //Left-Right input
private bool mDoLeftRightMove = false; //is moving Left or Right
private bool mDoStartMoving = false; //has simulation started
private Vector3 mDelta; // the movement delta every fixed update
In your Update() function check for left-right input.. (am assuming you are checking for Left-Right arrow keys only for now.. hence only checking the "Horizontal" axis)
void Update()
{
mLeftRightInput = Input.GetAxisRaw("Horizontal");
if (mLeftRightInput != 0)
moveLR = true;
}
Then in your FixedUpdate(), make the character move accordingly..
void FixedUpdate()
{
if (mDoStartMoving)//if simulation has started..
{
if (mDoLeftRightMove)
{
mDelta = transform.right * movingRate * mLeftRightInput;
mDoLeftRightMove = false;
rigidbody.MovePosition(rigidbody.position + mDelta);
EaseRotation(Quaternion.LookRotation(mDelta)); // this is simply Lerping the rotation in the direction of mDelta
}
else
{
mDelta = transform.forward * movingRate; //this will keep it moving in the forward direction
rigidbody.MovePosition(rigidbody.position + mDelta);
EaseRotation(Quaternion.LookRotation(mDelta)); // this is simply Lerping the rotation in the direction of mDelta
}
}
}
This still uses a rigidbody, but that's just because my thing was a physics simulation.. and its just easy that way! Hope this helps!
Answer by imyuva · Mar 28, 2013 at 02:41 AM
Restrict vertical
pragma strict function Update () { var zMove : float = Input.GetAxis("Vertical") Time.deltaTime 2; transform.Translate(Vector3(0,0,zMove)); transform.position.z = Mathf.Clamp(transform.position.z, 25, 550); }
Restrict Horizontal
pragma strict function Update () { var xMove : float = Input.GetAxis("Horizontal") Time.deltaTime 2; transform.Translate(Vector3(xMove,0,0)); transform.position.x = Mathf.Clamp(transform.position.x, 25, 550); }
In Mathf.Clamp(transform.position.x, 25, 550); set your coordinate boundry
Your answer
![](https://koobas.hobune.stream/wayback/20220612052709im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
change move controls relative to player 1 Answer
Kinect issue with Character Movement while in flight 0 Answers
"Energy" trail in character movement 1 Answer
Moving character with touch buttons (Android) 1 Answer
Getting My Character to Move 1 Answer