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 Maru07 · May 12, 2012 at 07:13 PM · axissidescrollerlocking

Make the Character not to move on the Z Axis [Locking Z Axis]

This may be the most banal Problem I ever had and it still doesnt leave me alone cuz I just cant fix it^^.

My Character Moves sometimes on the Z axis - its a sidescroller, so he shouldnt- sometimes when he collides with a stone or such, he slides arround it and... its really terrible. I really tried 1000 ways like Colliders on the side or with rigidbode-freeze Position or even with a simple script

function Update () { transform.position.z = 0; }

but somehow everytime the character is still able to move on the Z Axis.

Specially with the Script I thought it worked but then after some time, magicly, he fell right through a plane like nothing even happend^^ It really anoyes me because it eats my Time and Im not able to work efficient till this problem is fixed, so please community help me out Thxx =)

The Script that I use to Controll my Player http://jsfiddle.net/wx4gS/

Comment
Add comment · Show 2
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 Drakestar · May 12, 2012 at 07:23 PM 1
Share

You have to provide a lot more information about how you're moving the character to get meaningful feedback.

avatar image Maru07 · May 14, 2012 at 06:48 PM 0
Share

Sry - this is the script that i attached to the CharController http://jsfiddle.net/wx4gS/

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by timo0060 · May 14, 2012 at 07:25 PM

I had that same problem. My player would slowly move itself around the object. I solved it by doing this:

 var controller : CharacterController = GetComponent(CharacterController);
 
 moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,0);
 moveDirection = transform.TransformDirection(moveDirection);
 moveDirection *= speed;
 controller.Move(moveDirection * Time.deltaTime);

moveDirection can be replaced with your variable. The second line of code is pretty much saying that moveDirection can move on the x axis, not the y, or the z however. I hoped this helped you.

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 Maru07 · May 14, 2012 at 08:33 PM 0
Share

wow thx Im definitivly trying it out soon thx =) do I have to add this to the current script or is a seperate one appropriet

avatar image timo0060 · May 14, 2012 at 08:52 PM 0
Share

Just put this in the same script. So just replace where you set the values of your movement variable with my code, and just change the variable moveDirection from my code to movement so it matches your code. That should work. And just change you key bindings in your game so that Horizontal is equal to your joystick movement. If this solved it, up vote it so others who have the problem will know that this is a plausible solution.

avatar image Maru07 · May 21, 2012 at 09:43 AM 0
Share

No it doesnt work... maybe I imported your Script wrong have a look http://jsfiddle.net/$$anonymous$$aru07/mzGyh/

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

6 People are following this question.

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

Related Questions

Tree position on random Terrain (y axis) 0 Answers

Vector3.Angle, set range on individual axis 0 Answers

Lerp a Object along X and Z axis only. 3 Answers

Using Vertical axis in 2D only moves object by 0.1 1 Answer

Limit speed on x axis when applying force with gravity 0 Answers


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