Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by fran pugh · Feb 05, 2010 at 05:49 PM · movementcharacter

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!! :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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:

http://www.mixamo.com/c/unity

Cheers!

Stefano

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fran pugh · Feb 09, 2010 at 02:07 PM 0
Share

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

avatar image fran pugh · Feb 09, 2010 at 05:07 PM 0
Share

O$$anonymous$$ so am now getting somewhere with relative force and drag - thanks :)

avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fran pugh · Feb 05, 2010 at 08:13 PM 0
Share

awesome thanks, I'll give it a go :)

avatar image
0

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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges