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 Damonic217 · Apr 19, 2015 at 09:26 PM · javascriptcharacter movement

Cant Get Character To Move

Hi there, I'm quite new to 3d games and the models that come with them. The issues i'm having as the title says,i'm unable to get the character to move.

Originally I used a humanoid model and after watching some tutorials on how to get the character to move i found that this code, in javascript, did the job...

 function Update () 
 {
     if(Input.GetButton(LeftButton))
     {
         transform.rotation.y = LeftRotate;
         transform.Translate(Forward * MoveSpeed * DT);
     }
     if(Input.GetButton(RightButton))
     {
         transform.rotation.y = RightRotate;
         transform.Translate(Forward * MoveSpeed * DT);
     }    
 }

These are the values im using for interest sake.

 Forward = new Vector3(1,0,0);
     DT = Time.deltaTime;

I want the game to be 3d but from a 2d perspective so what code does is rotate the model to either left or right and move forward, and it worked. This morning I changed my model to a better suited model for my game, the model is Attack Bot from the asset store. The main difference between the attack bot and the humanoid model is that the attack bot is made of different pieces, for example the left wheel,right wheel,body, ect are separate parts whereas the humanoid was 1 object.

I've applied the movement code to the robot and it rotates him to the direction i want to go but he doesn't move. Im completely stumped as to what the issue could be.

I've attached a screenshot to give you a view of what i'm rambling about. ![A view of the Scene

Sorry for the long post, tried to get as much info in as I could. Thanks /D

error.jpg (198.8 kB)
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

1 Reply

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

Answer by maccabbe · Apr 19, 2015 at 10:28 PM

Since you state that you use DT=Time.deltaTime but it doesn't show up in your Update code, I'm going to assume you use it somewhere else such as Start or Awake.

Time.deltaTime is the time since the last frame so it changes from frame to frame. If you declare a variable DT that stores the value of Time.deltaTime and do not update it then the variable will copy the time since the last frame and keep it that way. If you attempt to use DT as though it has the current Time.deltaTime without updating DT then you are going to have the wrong value of DT. If you declare DT=Time.deltaTime in the first frame then since there is no previous frame the time since the previous frame is 0 which would result in all movements being multiplied by 0.

Change your code so it either updates DT in the Update function

 function Update () 
 {
     DT = Time.deltaTime;
     if(Input.GetButton(LeftButton))
     {
         transform.rotation.y = LeftRotate;
         transform.Translate(Forward * MoveSpeed * DT);
     }
     if(Input.GetButton(RightButton))
     {
         transform.rotation.y = RightRotate;
         transform.Translate(Forward * MoveSpeed * DT);
     }    
 }

or so it uses Time.deltaTime instead of DT

 function Update () 
 {
     if(Input.GetButton(LeftButton))
     {
         transform.rotation.y = LeftRotate;
         transform.Translate(Forward * MoveSpeed * Time.deltaTime);
     }
     if(Input.GetButton(RightButton))
     {
         transform.rotation.y = RightRotate;
         transform.Translate(Forward * MoveSpeed * Time.deltaTime);
     }    
 }

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 Damonic217 · Apr 20, 2015 at 05:29 PM 0
Share

Hi there, Thanks for the reply and I understand what you're saying about the Time.deltatime being in the update function and i'll keep it in $$anonymous$$d for next time. But alas the change didn't help, the robot still flips but doesn't move while the humanoid works correctly.

avatar image maccabbe · Apr 20, 2015 at 05:49 PM 1
Share

Check the values of $$anonymous$$oveSpeed, Forward, and DT

  if(Input.GetButton(LeftButton))
  { 
      transform.rotation.y = LeftRotate;
      transform.Translate(Forward * $$anonymous$$oveSpeed * Time.deltaTime);
      Debug.Log(Forward+" "+$$anonymous$$oveSpeed+" "+Time.deltaTime+" "+(Forward*$$anonymous$$oveSpeed*Time.deltaTime));
  }
avatar image Damonic217 · Apr 20, 2015 at 06:05 PM 0
Share

I saw what the error was thanks to the Debug.Log, I forgot to give movespeed a value so it was moving forward at 0. I feel quite silly >.< Thank you very much for your help !

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

19 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Translating Javascript code into C# Code 2 Answers

I'm trying to get an object to move using javascript however it won't move, can someone help? 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

JavaScript not working 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