- Home /
FPS substitute camera translation with rotation
Hi all, is it possible to use right/left arrow for rotate camera (not translate) in FPS script?...I need to use only the Keyboard (not mouse orbit). How can I do? thanks. Luciano
Answer by Slem · Nov 23, 2010 at 02:57 PM
moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical");
This keeps you from sidestepping.
Vector3 euler = transform.eulerAngles; //there are more ways of doing this, but I like euler
euler.y += Input.GetAxis("Horizontal") * RotationSpeed; //RotationSpeed is a public float
transform.eulerAngles = euler; //this sets the euler back. In c# you must do it this way. In unityscript you can do this transform.eulerAngles.y = value.
This handles rotation. Not tested, but should work.
EDIT: I have no knowledge of the script you are referring to, but I assume it's from the standard packages?. It's unityscript so not my speciality. But the same applies here. Where you take the input:
var directionVector = new Vector3(0, 0, Input.GetAxis("Vertical"); //remove the input from the x of the direction vector. This will only let you move in one axis. For the rotation part look in the script that do the translating now (if it's not the one you posted). You should be able to find some code rotating the player. Then apply the logic I've posted above. Good luck. With some trying and failing you will eventually succeed and have a better understanding for how things work.
yes It's standard FPS package...please, can you post the entire script (java o C#) that I can associate to the camera ins$$anonymous$$d of FPS standard script? I'm not a programmer...I'm sorry for dummy request!!!Thanks!
Answer by Luciano · Nov 23, 2010 at 03:13 PM
but where I have to put your code? ...I'm sorry I'm a newbie!!
this is the js scritp of FPS that I'm using:
private var motor : CharacterMotor;
// Use this for initialization function Awake () { motor = GetComponent(CharacterMotor); }
// Update is called once per frame function Update () { // Get the input vector from kayboard or analog stick var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
if (directionVector != Vector3.zero) { // Get the length of the directon vector and then normalize it // Dividing by the length is cheaper than normalizing when we already have the length anyway var directionLength = directionVector.magnitude; directionVector = directionVector / directionLength;
// Make sure the length is no bigger than 1
directionLength = Mathf.Min(1, directionLength);
// Make the input vector more sensitive towards the extremes and less sensitive in the middle
// This makes it easier to control slow speeds when using analog sticks
directionLength = directionLength * directionLength;
// Multiply the normalized direction vector by the modified length
directionVector = directionVector * directionLength;
}
// Apply the direction to the CharacterMotor motor.inputMoveDirection = transform.rotation * directionVector; motor.inputJump = Input.GetButton("Jump");
}
// Require a character controller to be attached to the same game object @script RequireComponent (CharacterMotor) @script AddComponentMenu ("Character/FPS Input Controller")
THANKS!!!
Answer by Luciano · Nov 24, 2010 at 03:25 PM
yes It's standard FPS package...please, can you post the entire script (java o C#) that I can associate to the camera instead of FPS standard script? I'm not a programmer...I'm sorry for dummy request!!!Thanks!
Your answer
Follow this Question
Related Questions
Double Dragon style Camera and movement 4 Answers
Possible To Add Move Functions To Camera? 2 Answers
Quaternion.LookRotation and Vector3.SmoothDamp Problems 1 Answer
third person controller like in Assasian's creed or GTA5 0 Answers
Rotating a camera and his object like an airplane simulator 2 Answers