Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 RockDude · Dec 08, 2011 at 04:25 PM · charactercontrollerx-axis

Move only x axis

Hi, how can I move my character only in x axis?...I have character controller and rigidbody on my player and now I want to add script that allows to move only in x-axis...I don't want to make my character rotate only move in X-axis.

Comment
Add comment · Show 1
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 robert_mathew · Dec 08, 2011 at 05:10 PM 0
Share

do you want automatic walk by the player or by key controll

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by FLASHDENMARK · Dec 08, 2011 at 05:41 PM

You did not provide any real information other than you want it to move in the X-axis-direction, so I'll have to work with what I got.

 var moveSpeed = 5.0;
 
 function Update (){ 
     transform.position.x += moveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime; 
 }

Very simple and basic, but maybe that'll be enough.

Comment
Add comment · Show 3 · 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 RockDude · Dec 08, 2011 at 06:55 PM 0
Share

It works when I don't have rigidbody...when I have rigidbody on my character then it falls through the terrain...

avatar image RockDude · Dec 08, 2011 at 07:12 PM 0
Share

What I am tring to do is that my character has rigidbody and character controller and I want to move character only in x-axis...Like FPScontroller only whitout z-axis

avatar image FLASHDENMARK · Dec 10, 2011 at 10:36 AM 0
Share

Using transform.postion blah blah, will make your object phase through all objects in the scene. If you are using a rigidbody you should use Rigidbody.AddForce(transform.right * 2500);

Or something similar.

avatar image
1

Answer by funkyllama · Dec 08, 2011 at 06:04 PM

If you already have your script that moves the character and you want to lock rotation axis and/or movement axis, then you can do this on the rigidbody itself within the inspector window. Rigidbody has constraints built in, so if you want to completely freeze any rotation & only allow movement on x, tick x, y & z in freeze rotation and tick y & z in freeze position. If it's a script you're after then the simple one OrangeLightning provided will do the trick. rigidbody constraints

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 RockDude · Dec 08, 2011 at 07:10 PM 0
Share

I don't want to really freeze y and z...I only want character to move x-axis...I still need Y and z axis.

avatar image
0

Answer by Andyvege · Feb 02, 2014 at 12:25 PM

So, i also want this (only allow the character to move along the x AND y axis.) but i add Rigidbody, and i open constraints and nothing happens when i check those boxes?!

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to not move on the x axis while not jumping 2 Answers

How do I stop a velocity only on the X axis? 2 Answers

my floating spaceship(charactercontroller) won't move in x direction... 1 Answer

3rd person Controler walk 0 Answers

Excluding Gameobjects/Colliders from reacting with Collision Flags? 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