unity-game-engineorthographic

How can i move orthographic camera like google map style in unity3D


I'm making an 3D game with theorthographic camera.

but i faced with some seriouse problem.

That is i can't move my camera like google map style(camera moves the opposite direction of dragging direction. and when i swipe screen fast, camera smoothly moves like it's on the ice. <- this is ideal movement)

Current logic that i'm using is like this;

  1. get a mouse position by GetMouseButtonDown() at the beginning

  2. get a target position by GetMouseButton() whlie i'm dragging the mouse. (with this, i can get the direction where should i move the camera)

at the same time i move camera to the target position by transform.position.

This logic is working fine but not quite like google map style. because once i end the drag, camera just stop.

How can i modify this logic? could you give me some help?

Sorry for my poor english skill...

What i tried.

  1. Attach rigidbody component to parent object of camera. and change the movement logic to velocity based from transform.position based. but i don't know why it's not working.

Solution

  • You need two states (minimum) with different logic for this:

    If you want to add something like "throwing" - you can try to analyze the last frame user's input delta (to check if the input was fast or not) and consider this in your calculations.

    The second state can be implemented by setting speed to your camera that will apply every frame. The faster the user input was - the higher initial speed will be. Just don't forget to set some max speed to prevent "teleportation" and to slow down your speed on a regular basis to make sure it will stop after some time.