hi all,
i’m a newbie and working on the first tutorial roll-a-ball. i’ve completed the first section of script to allow the ball to be moved. there appear to be no errors, but the ball will not move. i’ve found the input manager and checked what keys are being used (arrow keys and wasd), but i cant get the ball to move. i cant see what i am doing wrong. can anyone help please?
thanks
Since you’re new - are you sure that the controller script (“PlayerController.cs” from the tutorial) is attached to the ball and that the ball actually has Rigidbody and Sphere Collider components attached?
hi. no… the tutorial went from a blank/ new screen, step by step… but at no point did the tutor show that…
hi. i’m not sure… i’ll check those things and get back to you…
update: yes… the script is in the component list for the ball in the inspector window, along with rigid body and sphere collider. as a test i ticked gravity and started with the ball off the ground, and when i hit the play button, it fell to the ground, so the game is working… i just dont know why i am unable to move the ball with the keyboard…
Hmm - paste your entire “PlayerController.cs” contents and we’ll see if something is wrong.
thanks. i really appreciate your help. i wont be able to post it until tomorrow afternoon.
thanks again
No problem, I’ll keep an eye out.
hi…
this is the script for playercontrol:
using UnityEngine;
using System.Collections;
public class playercontrol : MonoBehaviour
{
void fixedupdate ()
{
float movehorizontal = Input.GetAxis(“Horizontal”);
float movevertical = Input.GetAxis(“Vertical”);
Vector3 movement = new Vector3(movehorizontal, 0.0f, movevertical);
rigidbody.AddForce(movement);
}
}
Thanks for looking at this.
Ah - rename your fixedupdate method to FixedUpdate. As a general convention method and class names are capitalized - it’s not really a rule of the language, it’ll compile without error, but in this case Unity is looking for a case-sensitive method name.
This should work:
using UnityEngine;
public class PlayerControl : MonoBehaviour
{
void FixedUpdate()
{
float movehorizontal = Input.GetAxis("Horizontal");
float movevertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(movehorizontal, 0.0f, movevertical);
rigidbody.AddForce(movement);
}
}
Good luck with the rest of the tutorials!
This has just solved my exact problem too. Many thanks Roland1234!
Thank you SO MUCH Ronald! I was stuck on this problem for hours. I had watched the video several dozen times and couldn’t find a solution. I finally realized that I had “fixedUpdate” instead of “FixedUpdate”
Once again, thank you! I was about ready to give up.
hello.
It has been a while since this thread has been touched (over a year) and in that time, Unity 5 came out.
Apparently, with Unity 5 some of the scripting changed, and when I used the code written here (and the one used in the default tutorial for roll-a-ball) Unity said it was using outdated code and decided to update it for me.
But now that problem from a year ago is back; the ball won’t move! The physics works and the wording on the code was barely changed (I’ll post it here in a second) but I just couldn’t get the thing to move!
Also, where can I find the input manager?
using UnityEngine;
public class PlayerControl : MonoBehaviour
{
void FixedUpdate()
{
float movehorizontal = Input.GetAxis(“Horizontal”);
float movevertical = Input.GetAxis(“Vertical”);
Vector3 movement = new Vector3(movehorizontal, 0.0f, movevertical);
GetComponent().AddForce(movement);
}
}
Thanks for the help!