- Home /
Question by
lucasmees · Sep 21, 2014 at 07:04 PM ·
2djavascriptmovementinput
how to move an object in 2D sense its position?
Hello, I'm creating a game with a two-dimensional craft similar to the arcade classic Asteroids mechanism. I was searching some forums, but found nothing on forward shift in position towards the front of the ship.
could someone help me? I need the script to be in javascript.
I already created the rotation of the sprite:
var speed = 100.0;
function Update ()
{
if(Input.GetKey("left"))
{
transform.RotateAround(transform.forward,0.01);
}
if(Input.GetKey("right"))
{
transform.RotateAround(transform.forward,-0.01);
}
var z = Input.GetAxis("Vertical") * Time.deltaTime * speed; transform.Translate(0, 0, z);
}
Comment
Your answer
Follow this Question
Related Questions
My controls are inverted when facing sideways. 1 Answer
When i make my character animated, he can only move up, down left and right (2D) (JS) 0 Answers
Prevent Player from moving into opposite direction than he already is 1 Answer
2d Movement Messes up when cube is rotatated 0 Answers
vertical and horizontal movement not working at the same time 1 Answer