|
Hello All...I am trying to create a simple version of a tank like controller. I originally just put in controls using the default inputs for the "vertical" and "horizontal",(arrow keys or WASD). I am pretty new to scripting in general so ... please be gentle. :)
Thanks for any help you can offer... Grateful Noob...
(comments are locked)
|
Set up "Left" and "Right" in the input manager. GetAxis isn't useful in this particular case since you need to check the keys individually. You generally don't want to use GetKey unless you intend on writing your own input manager. GetKeyDown (or GetButtonDown) won't work for this, because that only returns true for the one frame when you press the button down.
(comments are locked)
|
|
try: if(Input.GetKeyDown(KeyCode.A) && Input.GetKeyDown(KeyCode.D)){ controller.SimpleMove(forward * speed); } else if(Input.GetKeyDown(KeyCode.LeftArrow) && Input.GetKeyDown(KeyCode.RightArrow)){ controller.SimpleMove(forward * speed); } reason for else if instead of just another if, is because then you could (i think) be moving twice each frame if you held down all 4 keys. this will make it so that if you press A and D then you will go forward OR if you press left arrow and right arrow you will go forward. another way it can be done (but this is not for sure, its just a maybe) is: var curSpeed = speed * Input.GetAxis ("Horizontal") * -(Input.GetAxis("Horizontal")); use whichever way you want, first way will work for sure, but requires a little extra length, second way im not sure will work, but is a single line. hope this helps :) Unfortunateluy ... neither suggestion seems to be working... i try again tonite....
Dec 20 '09 at 04:32 PM
Shadyfella13
var speed = 3.0; var rotateSpeed = 3.0; function Update () {var controller : CharacterController = GetComponent(CharacterController); // Rotate around the y axis transform.Rotate(0, Input.GetAxis ("Horizontal") *rotateSpeed, 0); // Move forward var forward = transform.TransformDirection(Vector3.forward); var curSpeed = speed * Input.GetAxis ("Vertical"); if(Input.GetKeyDown(KeyCode.A) && Input.GetKeyDown(KeyCode.D)) { controller.SimpleMove(forward * speed); } else if(Input.GetKeyDown(KeyCode.LeftArrow) && Input.GetKeyDown(KeyCode.RightArrow)) { controller.SimpleMove(forward * speed); }
Dec 24 '09 at 08:25 AM
Shadyfella13
The above was my attempt at your first suggestion.n I get no errors, but the tank still wont move forward. Suggestions?
Dec 24 '09 at 08:26 AM
Shadyfella13
no idea then... I truthfully have no idea... should work, sorry i couldn't of been more use :(
Dec 27 '09 at 09:57 AM
m50
(comments are locked)
|
