So I have no code errors but when I test the game I cannot move the ball. I think I need to set up the input manager so Unity recognizes up,down,left,right keys or W,A,S,D.
also I have the public float speed but in the inspector (script) tab I do not have any speed value to set as the tutorial suggest it should.
I assume I have to enter some more code to assign buttons for directions and set a value for force.
How should I proceed so I can test the movement of the ball?
Again, anyone’s assistance is much appreciated as I’m stuck and really want to succeed.
The code runs without errors but I get the same error when I push buttons.
! The referenced script on this behavior is missing.
tried up,down,left,right and W,A,S,D
do not see any code for keyboard controls and I assume this is the issue. It is late and I have an early class so I don’t want to stay up too late. I will research keyboard button controls to see if I can figure out a solution as soon as I can.
If anyone has any insight into this it’s is always greatly appreciated, I feel I’m so close to getting the ball rolling, Literally!"
Sorry for being a newbie and not using code tags. I will always use code tags now thanks to Kdub.
It appears both my Horizontal and Vertical input were set to X axis. I changed The Vertical input to Y axis.
This issue is strange. If I hit play touch any button the error is displayed twice. However if I clear the error while in play mode and start using the directional arrows the camera moves around in scene view but nothing happens in game view.
I did it recently and it all worked as expected, read the errors. They should tell you what line is wrong. Syntax is everything in programming. Not only does case matter, the capitalization can mean the difference between describing the template for something and one instance of that thing.
If you want to make games, you need to start thinking like a programmer.
The most important thing Roll A Ball taught me was what CTRL-’ does in MonoDevelop.
Things aren’t moving. Why? What line actually moves something? In this case, AddForce.
It’s not working, why? Okay highlight AddForce. CTRL-'. API, what does Rigidbody.AddForce want? Is there an example? Try the example. Does it move now?
rb.AddForce(transform.forward * thrust);
Well, it wants a Vector3, so that must be what transform.forward is. Right away, knowing what transform.forward is seems pretty important, so go right to it’s API page.
The blue axis of the transform in world space.
Okay okay, it’s a Vector3 - otherwise AddForce wouldn’t work at all; but what exactly does it mean?
Debug.Log(transform.forward)
Ok, that works. Now back to my own Vector3. If I set it manually does the object move?
Work backwards and find where the chain is broken.
Found a guy who clarified it for me and made it easier to understand… Got the answer, here it is with the original code just slightly edited to comply with the updates.
Unity 5: This will not work in this current form. You cannot directly apply force to the rigidbody attached to an object if the script is also attached to the same object. Going forwards, you will need to assign the rigidbody as a property, and apply the force to the property. In order to do this, we use a public variable, the same way as speed in this video, to declare the rigid body:
public class PlayerController : MonoBehaviour {
public Rigidbody playerRigidBody;
…
Next, we change the code in the function FixedUpdate to apply force to the property instead of the rigidbody. The new line of code is:
The last thing to do is to return to Unity and find the Player Controller Script in the Inspector, when you have the Player object selected. AFTER you have added the rigidbody as a public variable to the code, a new property will appear called Player Rigid Body. Set this to the Player (Rigidbody) object by clicking the circle next to the field and clicking the relevant item from the list.