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 LPGaming · Jan 16, 2013 at 08:38 AM · javascriptmovementbasica

Basic movement not working?

So, This Basic Movement script, causes me to have a break-dancing cube which is uncontrollable.

 #pragma strict
 
 
 var speed = 1.0;
 var rotateSpeed = 3.0;
 
  function Update ()
  {
      var controller : CharacterController = GetComponent(CharacterController);
      transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
 
      var forward = transform.TransformDirection(Vector3.forward);
      var curSpeed = speed * Input.GetAxis("Vertical");
      controller.SimpleMove(forward * curSpeed);
  }
 
  @script RequireComponent(CharacterController)

Please note, this is BEFORE i hit a button aswell as after

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

3 Replies

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

Answer by LPGaming · Jan 16, 2013 at 10:03 AM

I figured it out, it's because I had a Box Collider already, and was using a script to create a CharacterController, My guess was that they were colliding with eachother, causing the Box Collider to "Bounce"

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 Lachee1 · Jan 16, 2013 at 09:32 AM

Instead of using Input.GetKeyDown(KeyCode.W) go trhough unity's inputs. so use this code instead,

 if( Input.GetAxis ("Vertical") > 0)//You only want the positive
        transform.position += transform.forward * moveSpeed * Time.deltaTime;

For more information, go to the GetAxis documentation, found here: http://docs.unity3d.com/Documentation/ScriptReference/Input.GetAxis.html

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 LPGaming · Jan 16, 2013 at 09:44 AM 0
Share

Not sure I understand which part of this will make it move when I hit W? didn't see that in the code the reference provided.

avatar image LPGaming · Jan 16, 2013 at 09:47 AM 0
Share

Also, this code just makes it move continuously without stop, so wouldn;t i still be using the GetkeyDown code?

avatar image
0

Answer by senad · Jan 16, 2013 at 09:34 AM

Your problem is not in this part of code, because it looks fine.

You should have a look at what changes you made between recently (start of broken behaviour) and now to find out what code broke your movement. :)

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 LPGaming · Jan 16, 2013 at 09:42 AM 0
Share

See that's the thing, I didn't do anything.... I just opened my project.... and Bam... Although I had a script that was doing the movement, I deleted it, because I had it turning by using the Transform.rotate(0, 90, 0); which was horrible, so I started changing it, that was also in C# and I moved to JavaScript to do movement because it seem easier, not having to make temeporary value for everything

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

10 People are following this question.

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

Related Questions

Object stops but then eventually breaks through 1 Answer

How to stop object from rotating during movement (Javascript) 1 Answer

Best Way to make a character move 1 Answer

Have a fixed object without interrupting the movement! 0 Answers

javascript for animating/moving non humanoid generic 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