- Home /
Question by
EliteHedgehog56 · Dec 26, 2017 at 06:28 AM ·
transformrotatechild
movement to certain child object
hi guys, I am attempting to replicate the controls of metroid prime (original gamecube version not MP trilogy version), I have the controls pretty much set up but when using the free aim controls when holding down the aim button it messes up the movement of my samus game object, because this is set to the root child it rotates the object, so when I start walking again it start ascending upwards, is there a way to change my script to send the movement to the camera child object.
here's the script
var canaim : boolean = false;
var canlock : boolean = false;
var normalmove : boolean = true;
var turn = 30;
var walk = 30;
var enemy : Transform;
var camera : Transform;
function FixedUpdate (){
if (Input.GetButton("Aim")){
canaim = true;
normalmove = false;
}
if (Input.GetButtonUp("Aim")){
canaim = false;
normalmove = true;
}
if (Input.GetButton("Lock")){
canlock = true;
normalmove = false;
}
if (Input.GetButtonUp("Lock")){
canlock = false;
normalmove = true;
}
if (normalmove){
if (Input.GetKey(KeyCode.D)){
transform.Rotate(Vector3.up * turn * Time.deltaTime);
}
if (Input.GetKey(KeyCode.A)){
transform.Rotate(-Vector3.up * turn * Time.deltaTime);
}
}
if (Input.GetKey(KeyCode.W)){
transform.Translate(Vector3.forward * walk * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S)){
transform.Translate(Vector3.back * walk * Time.deltaTime);
}
if(canlock){
transform.LookAt(enemy);
if (Input.GetKey(KeyCode.W)){
transform.Translate(Vector3.forward * walk * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S)){
transform.Translate(Vector3.back * walk * Time.deltaTime);
}
if (Input.GetKey(KeyCode.A)){
transform.Translate(Vector3.left * walk * Time.deltaTime);
}
if (Input.GetKey(KeyCode.D)){
transform.Translate(Vector3.right * walk * Time.deltaTime);
}
}
if (canaim){
if (Input.GetKey(KeyCode.D)){
transform.Rotate(Vector3.up * turn * Time.deltaTime);
}
if (Input.GetKey(KeyCode.A)){
transform.Rotate(-Vector3.up * turn * Time.deltaTime);
}
if (Input.GetKey(KeyCode.W)){
//modify this to rotate the camera child upwards
transform.Rotate(Vector3.left * turn * Time.deltaTime);
}
//modify this to rotate the camera child downwards
if (Input.GetKey(KeyCode.S)){
transform.Rotate(Vector3.right * turn * Time.deltaTime);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Error getting the transform of a child object. 1 Answer
2D platformer firing left and right, help! 1 Answer
Rotating a transform using it's child 2 Answers
Problem transferring children to a new parent 2 Answers
Spawn Shield to all objects 2 Answers