- Home /
Question by
pheeelthebern · Jun 29, 2020 at 09:27 PM ·
transformplayer movementnoobtop down shooter
(noob) Top down shooter player controller look at mouse script (2D)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerBehaviour : MonoBehaviour {
public float moveSpeed;
public Camera cam;
public Rigidbody2D rb;
Vector2 mousePos;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//takes input of horizontal axis and adds the value to the player's current position each frame
Vector3 moveHorizontal = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
transform.position += moveHorizontal * moveSpeed * Time.deltaTime;
//same thing but with the vertical axis
Vector3 moveVertical = new Vector3(0f, Input.GetAxis("Vertical"), 0f);
transform.position += moveVertical * moveSpeed * Time.deltaTime;
//creates a vector2 each frame with the current x and y of the players mouse
mousePos = new Vector2(Input.mousePosition.x , Input.mousePosition.y);
transform.LookAt(mousePos);
}
void FixedUpdate() {
//creates a vector2 each frame with the current x and y of the players mouse
}
}
When the game starts the player is immediately teleported far off-screen and seems to rotate around a specific point that I did not specify instead of rotating around the center of the player. I have no clue how to diagnose the issue I've tried multiple different scripts and they all have the same issue which makes me think it might be a problem with the player game object instead. Any help would be greatly appreciated, thanks for reading.
Comment
Answer by pheeelthebern · Jun 29, 2020 at 09:28 PM
comments are old btw so don't pay them any attention
Your answer
![](https://koobas.hobune.stream/wayback/20220613002103im_/https://answers.unity.com/themes/thub/images/avi.jpg)