- Home /
Sprite not displaying when I add a line of code that moves the main camera to another sprite
I'm in the beginning stages of writing a game and I'm having a bit of a problem. What is supposed to happen at this point is that the player sprite should fall towards the bottom of the screen with the main camera following and both the player and the camera should stop if the player collides with an obstacle. What is actually happening is that I can either have the player fall and collide with the obstacle but have the camera not follow or have the player fall and collide with an invisible obstacle and have the camera following.
I've narrowed down the problem to this code section: // Move vertically endPoint.Set(startPoint.x, startPoint.y - speed, startPoint.z); // Calculate the end point. Z never changes because this is a 2D game. X is changed via player input. transform.position = Vector3.Lerp(startPoint, endPoint, (Time.time - startTime) / duration); // Move the sprite camera.transform.position = Vector3.Lerp(cameraStartPoint, endPoint, (Time.time - startTime) / duration); // Move the camera speed = speed * rate; // Increase the speed
If I comment out the line starting with "camera" then I can see the obstacle, but the camera does not follow the player. If I do not comment it out, the camera follows the player but I cannot see the obstacle.
Click this link for a video showing the problem.
Any help would be greatly appreciated. Thank you!
Douglas Pope
Cross River Games
Lovrenc:
Thanks for your suggestions. I paused the game and rotated the camera like you suggested, and it looks like the player and the obstacle are coplanar, with the plane in question being parallel to the Y-axis. However, they are not; the player has a Z-value of 0 and the obstacle has a Z-value of -0.3. $$anonymous$$aybe that's the problem? The camera is orthographic, so the second suggestion does not apply.
EDIT: That was the problem! Thanks for the help!
Answer by Lovrenc · Aug 09, 2013 at 07:44 PM
Only 2 things come to mind:
Camera somehow gets rotated and your obstacle doesent have normals to face camera.
Camera gets moved to close to show obstacle. If it is ortographic make sure object is not behind the camera, if it is not orthographic, than you also have to take in account camera may be to close to get your object into the cone it records.
Start your game and pause it and then spin things around in editor view and see what is happening.