Rotate First Person Controller via script

Hi,

When I click on a GameObject, I want the position of First Person Controller sets to this GameObject.

function OnMouseDown () 
	{
		GameObject.Find("First Person Controller").transform.position = transform.position;
		GameObject.Find("First Person Controller").transform.rotation = Quaternion.Euler (0,90,0);
	}

In this code the position changes well but the rotation doesn’t work.

I want First Person Controller rotates to X axis direction. How can I do it?

Find the part in the Update void that says RotateView(); and then put and if statement in there or something like if (noRotateView == false) { RotateView(); }

@vahid62,

I have a script on my camera (MyCamera.cs) attached to the standard unity first person character controller. In that script I have just figured out how to set it.

My script (MyCamera.cs) needs reference to the Unity first person character controller script. So I added:

using UnityEngine;
using System.Collections;
using UnityStandartAssets.Characters.FirstPerson; //This

Then make a reference to the First person Controller Script.

public FirstPersonController fpc;

Actually open the FirstPersonController script attached to your playable character. Find the script reference:

private MouseLook m_MouseLook; 

Hover over the MouseLook and press F12 (to find) and set it to public from private.

Inside of the MouseLook.cs search for two private Quaternions:

private Quaternion m_CharacterTargetRot
private Quaternion m_CameraTargetRot;

In my script (MyCamera.cs) when I wanted the rotation to be zero i wrote in C#:
fpc.m_MouseLook.m_CharacterTargetRot = Quaternion.Euler(0f, 0f, 0f);
fpc.m_MouseLook.m_CameraTargetRot = Quaternion.Euler(0f, 0f, 0f);

This worked for me. It made the character and the cameras rotation back to zero.

the FPC has its own logic for movement. Trying to take it over is likely to lead to nothing but grief.

I recommend at this point you create your own using an object with a camera component, a capsule collider, rigidbody, and scripts to read controls and move it.

Hello dear

You can do it by using RotateAroundLocal

if you want rotate 90 degress around x-axis you can do like this

transform.RotateAroundLocal(Vector3.Right,wantedAngle);

Put the FPScontroller in an empty gameobject. Such a hack, but it works. At this time, I’m not actually clear on why FPScontroller ignores transform.rotation (?)