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 Corove · Aug 30, 2013 at 11:43 PM · movementsimplemove

Player turns but won't move forward

Hi there.

I just started with Unity today, and I started by watching all the tutorials. Now I'm following a little starting project guide I found (really basic). But I already have a problem with the SimpleMove function. So far I only have a plane for floor, and a sphere for player. My player will turn when I press the left/right buttons, but he won't move to the front or the back with the up/down buttons. I had some trouble with the simplemove function, but after looking it up in the reference I think the code is now okay. However, the problem is still there, my player will turn but won't move.

I even put my code in comment and tried to see if copying the code from the SimpleMove reference page of the website worked, but it still didn't work. So it doesn't seem to be a fault in the coding, but I don't really know where else to look... Maybe I need to import another package to the script, or there's some other component I need to add in the Inspector or something like that? (I've already done the charactercontroller)

 using UnityEngine;
 using System.Collections;
 
 public class Player_script : MonoBehaviour {
     
     public int speed = 3;
     public int rotatespeed = 3;
     
     void Start () {
         
     }
     
     void Update () {
         CharacterController controller = GetComponent<CharacterController>();
         transform.Rotate(0, Input.GetAxis("Horizontal") * rotatespeed, 0);
         
         Vector3 forward = transform.TransformDirection(Vector3.forward);
         float curspeed = speed * Input.GetAxis("Vertical");
         controller.SimpleMove(forward * curspeed);
     }
 }


While typing this, I just wanted to check if I really wasn't missing something stupid, and I just saw that there's an error when I press play:

"NullReferenceException: Object reference not set to an instance of an object Player_script.Update () (at Assets/Player_script.cs:19)"

I tried looking it up, but I didn't find anything relevant. The "at Assets/Player_script.cs:19" makes me think that the problem is on line 19 ( controller.SimpleMove(forward * curspeed); ), but I really don't find anything wrong with it?

I hope someone can help me soon!

Thanks in advance!

Corove

Comment
Add comment · Show 3
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 meat5000 ♦ · Aug 30, 2013 at 11:45 PM 0
Share

Do you have a character controller attached to your Player?

You should also look at the Character controller script to see what variable type the function Simple$$anonymous$$ove needs to work

avatar image getyour411 · Aug 30, 2013 at 11:46 PM 0
Share

Edit: oops just noticed line 14 you define controller. Do you have a CharacterController game component attached to this gameobject?

avatar image Corove · Aug 31, 2013 at 10:11 AM 0
Share

I just started Unity up to continue looking for the problem, and it worked... I don't really get it...

$$anonymous$$aybe something didn't load right, or I needed to refresh?

Anyway, it works now. I just hope I don't run into this often.

Thanks for the quick answers though!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ZachAttack9280 · Oct 27, 2015 at 03:09 AM

GUYS I FIGURED IT OUT IDK HOW BUT DO I DID THIS.

  1. I closed unity completely

  2. Shut off computer

  3. turn back on

  4. log back into unity

  5. open your project

  6. then it should be working again! this is what i did and it worked! goodluck:)

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

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Get a NaN error when unpausing a game 1 Answer

Making a bubble level (not a game but work tool) 1 Answer

SpeedUp (Beginner project RollBall) 2 Answers

Character Motor: standard vs. custom ? 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