I am attempting to replicate the gameplay style of the original metroid prime game on gamecube which I have pretty much sorted out but I am having issues with the free aim when holding down a key and locking onto the nearest enemy when holding down a button, In metroid prime if you hold down a certain button Samus would put her left hand on her cannon and is then able to freely look around on the spot and when holding down another button she can lock onto the nerest enemy, I know how to do the free aim the basic way by just adding the transform rotate action to the script but however this rotates the whole pefab and causes Samus to fall over. or cause her to levitate upwards when walking. Is there a way to make it only the camera child rotate ? also with the target lock how would I change it to lock onto the nerest enemy not just a set enemy
here is an example of what I basically want to achieve
[metroid prime gameplay][1]
[1]: https://youtu.be/fx0gqCllnl0
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){
// lock onto nearest enemy
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);
}
}
}
btw with the target lock can I add the motion to the camera only just like I want to do with the free aiming?
↧