- Home /
how to make an object move around
i have a sphere that i want to move by using either wasd or the arrow keys (which ever would be easier) i have a script that will move it in one direction with the space bar, but i want to move it in all directions. the script is
function Update ()
{
if(Input.GetButton("Jump"))
{
//do something
transform.position.z += 0.1;
}
}
Answer by fireDude67 · Dec 24, 2010 at 04:11 AM
Here is a line that moves something using both WASD and arrow keys:
transform.Translate(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
Also, you cannot modify the individual X,Y,Z components of a Vector3
You need to multiply by Time.deltaTime. Just adding +=1 is going to give you a bad result because frame rate varies from computer to computer and even within one computer depending on demands on the video card. Time.deltaTime removes that variability. Same with the example that fireDude67 gave you.
Answer by MRProproduction1 · Mar 18, 2013 at 09:15 PM
just fort I am new to code what about useing first person control just delete camra and chage the wasd to the arrows just a fort
Answer by guillendavid694 · Aug 14, 2018 at 11:10 PM
I can't make this one line work,I can't make this one line work...
Your answer
![](https://koobas.hobune.stream/wayback/20220613092354im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to move an object towords another using forces 0 Answers
How to move an object in world with script 1 Answer
2d Platform Controller Face Help 1 Answer
How can I move a corresponding object. 2 Answers
Make Arms Move Slow 0 Answers