Question by
smsyaz1 · Jul 12, 2021 at 01:28 AM ·
camera-movementtop down shooter
How to make camera follow in between cursor and player
Hello and just a quick note that I'm quite new to unity and coding, if possible please explain simply. I'm making a topdown shooter and I want to make the camera follow in between the player and the cursor, but I don't know how. I've already made the player movement and player rotating towards the cursor. Here is my Player movement script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerMovement : MonoBehaviour
{
public float moveSpeed = 5f;
public Rigidbody2D rb;
Vector2 movement;
Vector2 mousePos;
public Camera cam;
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.deltaTime);
Vector2 lookDir = mousePos - rb.position;
float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg;
rb.rotation = angle;
}
}
Sorry if my English is bad.
Comment
Answer by smsyaz1 · Jul 12, 2021 at 08:06 AM
nvm fixed : https://www.youtube.com/watch?v=LFe017d-S58
incase anyone has the same question
Your answer
