So I’m creating a top-down shooter and trying to make the player face the direction of the joystick. You walk with the left stick and aim with the right stick. My goal is to have it so that if you, let’s say, turn the stick to the right your character would look right. This is my current code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(PlayerMotor))]
public class PlayerController : MonoBehaviour {
Camera cam;
PlayerMotor motor;
void Start () {
cam = Camera.main;
motor = GetComponent<PlayerMotor>();
}
void Update () {
//movement
motor.MoveToPoint(new Vector3(transform.position.x + Input.GetAxis("Horizontal"), transform.position.y, transform.position.z + Input.GetAxis("Vertical")));
//cam control
cam.transform.position = new Vector3(transform.position.x,
transform.position.y + 9.0f,
transform.position.z);
//this is the problem
transform.Rotate(new Vector3(transform.position.x + Input.GetAxis("rightStickHorizontal"), transform.position.y, transform.position.z + Input.GetAxis("rightStickVertical")));
}
}
for some reason when I do this it just turns ever so slowly in the direction of the joystick (appears to be 1 degree per frame).
,So I’m creating a top-down shooter and trying to make the player face the direction of the joystick. You walk with the left stick and rotate with the right stick. My goal is to have it be so that if you point the right stick towards the, let’s say right your character would look right. this is my current code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(PlayerMotor))]
public class PlayerController : MonoBehaviour {
Camera cam;
PlayerMotor motor;
void Start () {
cam = Camera.main;
motor = GetComponent<PlayerMotor>();
}
void Update () {
//movement
motor.MoveToPoint(new Vector3(transform.position.x + Input.GetAxis("Horizontal"), transform.position.y, transform.position.z + Input.GetAxis("Vertical")));
//cam control
cam.transform.position = new Vector3(transform.position.x,
transform.position.y + 9.0f,
transform.position.z);
//this is the problem
transform.Rotate(new Vector3(transform.position.x + Input.GetAxis("rightStickHorizontal"), transform.position.y, transform.position.z + Input.GetAxis("rightStickVertical")));
}
}
for some reason when I do this it just turns ever so slowly in the direction of the joystick (appears to be 1 degree per frame).