Roll-a-ball question

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?

Do you have the method names capitalised properly in your script? update will not work, Update will.

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().xxx

Thanks for your response. Unity seems to have autocorrected the code itself with the GetComponent yet it still does not play. Any ideas?

Can you share your code? Use the code tag button to make it readable.

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().AddForce(movement * speed * Time.deltaTime);

}

}

Fixedupdate should be FixedUpdate.

Like this?

2012179--130008--playercontroler.cs (398 Bytes)

Hmm ok thank you! Let me try now.

Well that worked but now it looks like my camera is looking out from the ball. I'm not sure why...

No. This made no difference. Any other thoughts?

Says the reference script on this behavior is missing

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, void Fixedupdate () needs to be void FixedUpdate ()

Also, your class name is public class Playercontroler but is this correct as it should be public class PlayerController and the script name needs to be the same PlayerController.cs

1 Like

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.

@ethancodes

Yes you have the exact same problem ...

void start() should be void Start()

You need upper case S on start.