Child OWN Rotation
Hello everyone, i'm new in Unity and i'm trying to do this : I have a Capsule and a Camera. The Camera is a child of the Capsule adn when i try to rotate the Camera with a C# script with transform.rotate the camera rotates, but the Capsule rotates too ! How i can i block the rotation of the Capsule and make it stay in his start position ? I've tried to block the rotations in the rigidbody options but it ain't work :(
Is your script on the Capsule? If you are rotating transform.rotation
, then you need to make sure the script is on the Camera. This is because transform
is a variable that applies to the Object your script is attached to.
If your script is on the Capsule and you are rotating transform.rotation
, then you're changing the local rotation of the Capsule.
The script with transform.rotation in on the camera , on the capsule i got a script for the movement with tranform.translate :/ I can show u the 2 script if u want
So there it is, the camera is a child of the capsule. CA$$anonymous$$ERA SCRIP : using UnityEngine; using System.Collections;
public class PlayerControl : $$anonymous$$onoBehaviour {
float xRotation;
float yRotation;
float sensitivity = 5.0f;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
Look();
}
void Look() {
xRotation -= Input.GetAxis("$$anonymous$$ouse Y") * sensitivity;
yRotation += Input.GetAxis("$$anonymous$$ouse X") * sensitivity;
xRotation = $$anonymous$$athf.Clamp(xRotation, -90, 90);
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
}
}
CAPSULE SCRIPT : using UnityEngine; using System.Collections;
public class Player$$anonymous$$oveControl : $$anonymous$$onoBehaviour {
float x$$anonymous$$ovement;
float z$$anonymous$$ovement;
public float speed = 5.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
$$anonymous$$ove ();
}
void $$anonymous$$ove(){
x$$anonymous$$ovement = Input.GetAxis ("Horizontal") * speed * Time.deltaTime;
z$$anonymous$$ovement = Input.GetAxis ("Vertical") * speed * Time.deltaTime;
transform.Translate (x$$anonymous$$ovement, 0f, z$$anonymous$$ovement);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612085813im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Camera Controller script as a child object,Camera Control as a Child Object for my Player 0 Answers
How to rotate camera view? 0 Answers
Having problems with doing a smooth isometric rotation around player 0 Answers
Child always on parent top to get the number of dice 0 Answers
How do I make the camera look at three possible perspectives? 0 Answers