- Home /
How do you fix a sprite to a camera that follows another sprite, but still be able to move it?
I'm attempting to create a 'pong' style game where you have to hit the ball up towards the top to the finish. This means that I require the camera to follow the ball on the y-axis, and I've managed this, but it leads to the paddle being left behind and not be shown in the camera. I need to have the paddle fixed to the borders of the camera but also be able to move it freely without the speed of the camera ascending/descending affecting them. I am very new to C# and unity and am finding it hard to wrap my head around what to do and how to do it.
This is my code that I've tried, any responses are appreciated:
Vector3 temp = transform.position;
offset = cameraPos.position.y - temp.y;
if (moveUp == false)
{
temp.y = cameraPos.position.y;
temp.y += offset;
transform.position = temp;
}
if (moveDown == false)
{
temp.y = cameraPos.position.y;
temp.y += offset;
transform.position = temp;
}
Your answer
Follow this Question
Related Questions
Why sprites are getting blur when camera is in motion? 0 Answers
Sprite managed by Sprite Renderer doesn't shows up in play mode 0 Answers
2D game camera background between sprites 0 Answers
Unity 2D: query for "mask/layer" bit on screen space without collider 1 Answer
How do I get the sprite pointing the right direction? 1 Answer