Hi I'm having problem Translating and Positioning at the same time e.g take example of retro spacecraft shooting games in which your spaceship moved in x-axis automatically and you just needed to control position on y-axis. I'm using transform.Translate(new Vector3(0f,Time.deltaTime * speed,0f),Space.World); to translate and then transform.position = new Vector3(Input.mousePosition.x,0f,0f); to position using mouse but it doesn't seem to work. Help !
|
|
||||
|
|
|
Actually what you will find is that the spacecraft does not move at all in retro space shooters; but rather all of the level objects move in the opposite direction instead. i.e. To make it look like the player is moving right; you should make all of the level objects (including the background) move to the left. So really you shouldn't need to be translating the player on the X axis at all. You should be translating the level objects in the opposite direction on the X-axis instead. This will also make positioning the player, using the mouse position, a lot easier as you can work using absolute screen co-ordinates, without having to worry about the player's world co-ordinates. EDIT: If you really must move the player's position physically in the world, then I would suggest that you grab the position of the mouse on the screen, then add it to the offset of the view, to set the player's world position correctly, combining them into a single transformation such as:
|
||||
|
|
Both What you want to do is change your mouse input code to take into account the current y and z values of your position. So do the translate part, and then for setting the x value, do something like this:
Keep in mind that it's very likely that |
|||
|
|