Hello ,
I am Karan
and I want make a 3d game In which I want my player and camera to rotate when my player
reaches a designated place.
But ,
I have set the rotation angle instead it is moving at the wrong angle
And If you want Script or project file i can give.
mgear
2
Hi,
yes, post script so can check.
and for scripts, use forum code tags:
Player Script:
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[SerializeField]
float PlayerSpeed;
Transform PlayerTransform;
[SerializeField]
Transform Camera;
public static bool MovementEnable;
private void Start()
{
PlayerTransform = GetComponent<Transform>();
}
void Update()
{
if (MovementEnable == false)
{
Movement();
}
if (PlayerTransform.position.x == 35.5f)
{
Camera.Rotate(0,90,0,Space.Self);
}
}
void Movement()
{
Vector3 GetInput = new Vector3(0, 0, Input.GetAxisRaw("Vertical"));
Vector3 Direction = GetInput.normalized;
Vector3 Velocity = Direction * PlayerSpeed;
Vector3 MoveAmount = Velocity * Time.deltaTime;
transform.Translate(MoveAmount);
}
}
Camera :
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
[SerializeField]
Transform Player;
Vector3 offset;
private void Awake()
{
offset = transform.position - Player.position;
}
private void Update()
{
transform.position = Player.position + offset;
}
}
mgear
4
do you want to set camera rotation to: 0,90,0
or rotate 90 degrees on y axis, did you try using Space.World?
or maybe just easier to set look at direction,
Camera.LookAt(yourtarget);
1 Like