I’m following the roll a ball game tutorial. Everything was working fine until it came to the camera. To start, for some reason my camera was on ortho mode, so I changed it to perspective.
I can see the preview of the camera in editor mode, and it shows the right perspective of the ball on the plane. But once I add the camera control script into the camera, and set the player as the focus point. When I hit play it shows only a zoomed in shot of the plane and I can’t see the ball anywhere.
so offset is the variable, but when you type offset = transform.position
Does that mean you are setting variable as a vector3 position, or that you are accessing the position property and then setting offset as the player’s position value?
Let me know if that doesn’t make sense, i’ll try to word it better. Thanks!
Please use code tags for code, it makes it easier to read.
Your code makes no sense at all. In LateUpdate, you’re setting the camera’s position to the player’s position, you’re setting it to “offset”. “offset” is the player’s position. You clearly have no idea on what you’re doing.
What you probably want is something like this:
public Vector3 Offset;
public Transform PlayerObject;
void LateUpdate()
{
transform.position = PlayerObject.position + Offset;
}
All that part does is set the camera’s position to exact player’s position, and then stores that position in offset. Offset really serves no purpose the way you’re using it in your code. Follow the above suggestion by DroidifyDevs e.g.
That won’t help you because you aren’t setting your offset correctly. You’re setting the offset to the player’s start position, then you’re adding that to the player’s position every frame of the game. You’re going to get some very strange results with that.