I am working through the roll a ball tutorial and am having issues with the camera. I just wrote the script for the main camera and assigned the player game object to it, but the camera is not moving with the player. It just stays still. The only difference I can find in the video is that there is a check mark by the script at the bottom of the inspector, on mine it is not giving me an option to check mark it. any ideas?
I was just curious, Is the roll a ball tutorial valid for the Unity 5.0 version? I am also having trouble. I have followed the code instructions and the ball refuses to move still.
There are two key broken points in Roll-A-Ball. The first one from 4.6 is the use of the obsolete GUIText. Updaterd video here. www.youtube.com/watch?v=IViD5G2ucNs The second from 5.0 is the outdated API. Instead of rigidbody.xxx you must now use GetComponent<RigidBody>().xxx
Thanks for your response. Unity seems to have autocorrected the code itself with the GetComponent yet it still does not play. Any ideas?
this is the code now. usingUnityEngine; usingSystem.Collections; publicclassPlayercontroler : MonoBehaviour { publicfloatspeed; voidFixedupdate () { floatmoveHorizontal = Input.GetAxis("Horizontal"); floatmoveVertical = Input.GetAxis("Vertical"); Vector3movement = newVector3(moveHorizontal, 0.0f, moveVertical); GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime); } }
The file name and class name have to match exactly You currently have Playercontroler in your script and playercontroler as the file name.
So upper/lower case is important, as is proper spelling. As mentioned above, Code (csharp): void Fixedupdate () needs to be Code (csharp): void FixedUpdate () Also, your class name is Code (csharp): public class Playercontroler but is this correct as it should be Code (csharp): public class PlayerController and the script name needs to be the same Code (csharp): PlayerController.cs
soooo anyways...back to the original question that I'm still having issues with...lol. My camera is still shows as a first person from the balls perspective, but not rotating with the camera. It stays level while the ball rolls. Here is my code: using UnityEngine; using System.Collections; public class MainCamera_Script : MonoBehaviour { public GameObject player; private Vector3 offset; void start() { offset = transform.position; } void LateUpdate() { transform.position= player.transform.position + offset; } } And everything on the Inspector matches what is shown in the video.
In the inspector for the camera, did you change the Transform and move it back and up so it starts in the proper position that you want it too?
yes I did. I think what is happening is its reading the offset as 0. because when I press play the main camera moves to the same location as the ball and then moves with it but remains forward facing. Is there a way to set the offset that I am missing?
I don't have a solution, but I'm having this exact same issue. hopefully we'll get a reply soon. Edited to Add: I searched a little deeper in the forums and found this ( http://forum.unity3d.com/threads/roll-a-ball-camera-offset-problem.297034/ ) thread, which contained a solution that worked for me.
@GetOverHere89 Yes you have the exact same problem ... void start() should be void Start() You need upper case S on start.
I was having similar issues where it looked like the ball was floating in midair then after about 30 seconds it would drop through the floor. Turns out it was the game camera angle playing optical illusion on me. Once I changed the angle of camera I could see that the ball was always moving and when it fell through, it actually just hit the edge of the plain. Felt very foolish about this.
I am having a different issue now. I am working on the collecting part of the tutorial and I had it to the point where I could go through the cubes, but without the collider portion. But now I can't get the game to run due to CS1061 error: " Assets/_Script/playerctrl.cs(23,31): error CS1061: Type `UnityEngine.Collider' does not contain a definition for `gameobject' and no extension method `gameobject' of type `UnityEngine.Collider' could be found (are you missing a using directive or an assembly reference?) " I'm not sure as to what I changed to cause this error to happen. I do have my prefab made and tag set at "PickUp", Box Collider is on; Added the Rigidbody and clicked on Is Kinematic as well. Here is my code: using UnityEngine; using System.Collections; public class playerctrl : MonoBehaviour { public float speed; void FixedUpdate () { float moveHorizontal = Input.GetAxis ("Horizontal"); float moveVertical = Input.GetAxis ("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical); GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime); } // Destroy everything that enters the trigger void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "PickUp") { other.gameobject.SetActive(false); } } }
If I'm not mistaken, it's most likely because you typed gameobject instead of gameObject in Line 23. Try this: Code (csharp): void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "PickUp") { other.gameObject.SetActive(false); } } For future reference, you can format codes with the code tags [code ] and [/ code] (without the space); it would make things easier for others to read particularly if you are quoting the line number(s) shown in the debugger! Feeling silly is part of learning - I still do amazingly silly things after a few weeks and probably won't stop doing that for a while. xD