Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to make 2D Top-down shooter controller with camera follow?

Discussion in 'Scripting' started by KOR_APUcard, Apr 24, 2019.

  1. KOR_APUcard

    KOR_APUcard

    Joined:
    Jul 21, 2018
    Posts:
    9
    How to make 2D Top-down shooter controller with camera follow (And camera follow cursor.)? Like a diep.io, etc. (But little bit different.)
    Using movement key is WASD.

    I'm planning college group task. (And my department is Computer Programming.) My teammates are 3 people including me. But my team does not much know how to write a script. They also have the same department as me.
    I want to make a better game, but sometimes I get confused. Can somebody help me? (I'm still confused.)

    I'm using Unity 2018.3.12f1 (x64 Windows).
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
    Like a regular camera follow, but camera should actually follow a point inbetween the cursor and the player. You'll need the following.

    1. create a Ray object going from camera through mouse cursor
    2. Physics.Raycast that ray to the ground and find where on the ground the cursor points
    3. lerp some position between the player and that point. 25% is nice, for example
    4. move the camera to that position and offset up to the desired height
    5. set camera forward vector to minus offset
     
  3. KOR_APUcard

    KOR_APUcard

    Joined:
    Jul 21, 2018
    Posts:
    9
    Can you show example to me?
     
  4. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
    KOR_APUcard likes this.