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 KrazyKain · Mar 01, 2010 at 03:52 AM · movementbugcharacter

character controller randomly flies up

Ok so I've got a topdown camera, and a sphere with character controller component and this script attached to the sphere:

var speed = 5.0;

function Update () { var controller : CharacterController = GetComponent(CharacterController) ; var x = Input.GetAxis("Horizontal") Time.deltaTime speed; var z = Input.GetAxis("Vertical") Time.deltaTime speed; var vec = new Vector3(x,0,z);

controller.Move(vec);

}

The sphere is on a flat plane, and theres some static cubes attached to all sides (walls).. at first I thought this happened every time I bumped the sphere into something, but after playing around I realized it's not upon bumping, but upon going backwards (i.e. the direction the sphere is NOT pointing), what happens is that it flies upwards towards the screen. I really dont see how where it's facing can affect its Y access movement as the code clearly only alters the X and Z axis

any idea what's causing this?

extra info: all walls have mesh colliders Tried this again with a cube, it took longer to happen (where with the sphere it happend instantly when i moved backward, with the cube i had to move around alot before i noticed it elevated) There is a script attached the camera that forces the sphere to look at the mouse pointer (surely this is irrelevant when the move script ignores the sphere's direction)

Update: Now i realize that it's not when moving back only, but also right, not sure what this means exactly.

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 GamezGlitchZ · Jun 30, 2014 at 10:04 PM 0
Share

nope still didnt work for me, my character still flying up or when i look up and run it runs into the air and then SLOWLY falls down...

3 Replies

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

Answer by Motionreactor · Mar 01, 2010 at 11:40 AM

Whilst I'm not sure why your controller was heading skyward (y axis)... the problem you have is this:

controller.Move()

I don't know the innards of the Move() function, but basically it seems to be expecting a 'world space' transform vector. So all you need to do is convert the Input.GetAxis() vectors from local to world space like this:

var speed = 5.0;

function Update () { var controller : CharacterController = GetComponent(CharacterController) ; var x = Input.GetAxis("Horizontal") Time.deltaTime speed; var z = Input.GetAxis("Vertical") Time.deltaTime speed; var vec = new transform.TransformDirection(Vector3(x,0,z));

 controller.Move(vec);

}

http://unity3d.com/support/documentation/ScriptReference/Transform.TransformDirection.html

Comment
Add comment · Show 7 · 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 KrazyKain · Mar 01, 2010 at 03:06 PM 0
Share

The problem with using transform over $$anonymous$$ove is that my character then ignore's the mesh collisions and moves right trough them, plus using transformDirection makes it move the direction it's facing, I want it to move up down left right regardless of where its facing. (when I first tested with translate, I used Space.world to accomplish this, but still had the problem where it ignored collisions) Thanks alot for taking the time anyway

avatar image Motionreactor · Mar 01, 2010 at 03:20 PM 0
Share

Oops, sorry that line was actually meant to have "controller.$$anonymous$$ove(vec);". I had forgotten to fix that, as I had changed it temporarily to "transform.Translate(vec)" only for comparative testing. So I edited the answer above. It should work fine now.

avatar image KrazyKain · Mar 01, 2010 at 03:27 PM 0
Share

this still seems to result in the character moving on his own access ins$$anonymous$$d of the world space.... and for some reason still flies upwards when moving back. you can't think of anything outside of the code that might be causing this?

avatar image Motionreactor · Mar 01, 2010 at 03:33 PM 0
Share

I duplicated your setup by creating a new scene using the standard assets 'first person character controller' prefab and then attached your extra script. It behaved strangely until I made that change, but it never altered the y transform. There must be something awry somewhere else in the project. Perhaps another script is changing the y transform. You could also check: edit > project settings > input. Settings appear in the inspector window.

avatar image KrazyKain · Mar 01, 2010 at 03:53 PM 0
Share

ok well thanks for confir$$anonymous$$g its not the script, atleast I can stop trying to fix that and look elsewhere... I'll keep you updated

Show more comments
avatar image
4

Answer by pyro · Apr 25, 2010 at 03:09 PM

Check your character controller's gameobject's children for any rogue colliders. It sounds like you might have created a sphere gameobject (gameobject->create other->sphere, which comes with a sphere collider attached) and then attached that to your character controller.

What then happens is your character controller bumps into those rogue colliders, causing it to try to climb over itself... which could explain your Y axis jumps.

You can alternately test this theory out by changing the Step Offset in the Character Controller to 0 and that might fix your jumps as well.

Comment
Add comment · Show 6 · 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 fucrate · Oct 08, 2010 at 09:08 PM 0
Share

nice, this fixed my problem AND i like the term "rogue colliders"

avatar image UltimateBrent · Dec 17, 2010 at 08:40 PM 0
Share

I had the same issue, thanks so much!

avatar image TMPxyz · Jul 29, 2012 at 01:03 AM 0
Share

works like a charm!!

avatar image fueldown · May 20, 2013 at 01:45 PM 0
Share

@pyro: you, sir, take my like. I was banging my head all day trying hell lot of different things. This resolved my problem. Cheers!

avatar image beosabre · Feb 10, 2014 at 11:02 PM 0
Share

Setting Step Offset to 0 in the Character Controller worked! (i.e. the Controller was flying/bounding upwards)

Show more comments
avatar image
0

Answer by h4wkeye · Mar 25, 2011 at 10:09 AM

flyhax.

/thread

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I fix the Unity Bug 1 Answer

Character controller + animation of different meshes making one character 1 Answer

about character movement in 8 direction 1 Answer

Movement Script for Character Motor 1 Answer

I want to play an Audio Sound for a character while running. 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