- Home /
An object who stay in the camera area
Hello
I'm making a shoot them up game and I want that my ship stay in the camera area
I know that I must use Camera ScreenToWorldPoint but I don't know how
Thank you
2D Game? 3D game? Sideview? Top? Free movement within the camera view? Following Ship?
And if you need to use ScreenToWorldPoint (which i doubt you need), then I suggest you check it up in the Unity.Doc (Help/ScriptReference). It basically used a camera of your choice, takes a Vector2 position ( Using pixel values ) and converts them to a Vector3 position.
With this description, it is difficult to help you. What is moving? The ship? The camera? When do you want to do the correction? How is the ship moved? Using a Rigidbody and adding force or are you directly manipulating the transform? You might want to take a look at:
2D Game Front view with an ortographic camera, the camera is moving with a Vertical Scrolling, the ship with a rigidbody is moving too
Viewport coordinates go from (0,0) in the lower left to (1,1) in the upper right. So you can tell if you are nearing the edge of the screen. Using a Rigidbody() makes the problem somewhat more difficult. You either have to change the velocity of the ship or change the speed of the camera as the ship approaches an edge.
and How I can limited the movement of the ship with that ?