I am writing a game for a young man with cerebral palsy. He can interact with the computer using two switches that I have mapped to the 'a' and 'b' keys. I want to have the character of the game move foreword a grid space (an arbitrary amount as he may or may not gold down the switch) when he hits the 'a' switch and have the character move 90 degrees to the right when he hits the 'b' switch. The camera needs to follow the character from above or behind. The character needs to follow the ground in an attempt to get out of a maze. I have tried to do this myself and have have no success. Any advice would be appreciated. If you need any further information please email me at: shawn@ampertec.com Thanks
I can help you with the basic movement part ... create a script with this in it and save it as MoveForward.js. Then create a new tag in the Inspector and call it "Character". Select the charcater object and assign it this tag in the top panel of the Inspector. Code (csharp): // a script that moves a character a set amount forward // when the mouse button is pressed function OnMouseDown () { target = GameObject.FindGameObjectWithTag ("Character").transform; target.transform.localPosition.z += 10.0; } A simple example of the camera following can be found in the second Scripting tutorial on pages 16-17. It's exactly what you want. Replace 10 with whatever distance you need. But this will work on the click down, maybe is should be on the release of the button? Do you want the 90° right movement to be proceeded by a turn to that direction then a move? If not, just change the z in the above code to x. Feel free to email me as well.
Thanks for the response. I need the foreword movement of the character to be controlled by an 'a' keystroke. The 'b' keystroke needs to rotate the character 90 degrees to the right. I believe that the combination of the two keystrokes should let my friend navigate (although slowly if he needs to turn left) around the game I hope to make for him. I'll check out the camera follow example you suggested. Thanks, Shawn
http://www.otee.dk/Documentation/ScriptReference/Input.html#GetKeyDown This explains how to substitute a key instead of mouse input.
Very nice project. Try this: Code (csharp): var walkStep = 10.0; var angleStep = 90.0; function Update () { if (Input.GetKeyDown("a")) { transform.position += transform.TransformDirection(Vector3.fwd * walkStep); } if (Input.GetKeyDown("b")) { transform.RotateAround(transform.position, Vector3.up, angleStep); } } Create this JavaScript as RotateAndWalk.js (or something like that) and drag it onto any object. That object should now move around when you press A and B. The script has two properties which you can edit in the inspector to tune the movement (step size and rotation amount). Hope it makes sense. d.