Need Help Badly! Unity Basic Game!!!

Hello, im new to unity and I’ve tried at least 3 different codes to get my “frog” to move freely on the plane and even used the ( Programmer's Ranch: Unity3D: Moving an Object with Keyboard Input ) Tutorial and nothing helps! All im trying to do is make my box move up, down, left, and right! I would perfer a JavaScript script and not C#… Here is another code im using thats not working,

var frog : Transform;

function Update() {
// we run input GetKeyDown in Update function as the true value will be reset after each frame
// Update is run per each frame
// when player presses up key move the frog forward one unit
// you can increase the units moved by doing this:
// Vector3.forward * 1.5f
if(Input.GetKeyDown(“up”)) {
frog.position = Vector3.forward * 1.5f;
}

if(Input.GetKeyDown(“down”)) {
frog.position = Vector3.back * 1.5f;
}

if(Input.GetKeyDown(“left”)) {
frog.position = Vector3.left * 1.5f;
}

if(Input.GetKeyDown(“right”)) {
frog.position = Vector3.right * 1.5f;
}
}

What happens here is my “frog” Jumps to a certain spot and and wont move… i want my frog to move freely !! Can somebody please help? Thank you!!

frog.position = Vector3.right * 1.5f;

you’re not setting a relative position from the frog, you are setting an absolute position 1.5 units right of global origin…

try

frog.position = frog.position + (Vector3.right * 1.5f);
or
frog.position += Vector3.right * 1.5f;

(there are other issues, but that’s the core of the one you asked about and I have to head off)

thank you but like i said im fairly new and im trying to punch in the code u gave me and im getting all types of errors … =[

Thats one of the problems i had with Unity when i started.

There is difference between:

DIRECTION

and

POSITION

Direction
Your object is “going somewhere” so you have to declare some direction with a vector like Vector3(0,1,0). That mens your object is GOING TO GO in the direction of “y”. Meaning “UP”.

the shorthands for writing the directions are:

Vector3.back = Vector3(0, 0, -1)
Vector3.down = Vector3(0, -1, 0)
Vector3.forward = Vector3(0, 0, 1)
Vector3.left = Vector3(-1, 0, 0)
Vector3.one = Vector3(1, 1, 1)
Vector3.right = Vector3(1, 0, 0)
Vector3.up = Vector3(0, 1, 0)
Vector3.zero = Vector3(0, 0, 0)

Position
Is the position your object is AT THE VERY SECOND YOU CHECK IT. This can be a vector3 like "position is Vector3(21,10,37). That means the object is at the positions

x = 21,
y = 10,
z = 37

In the “world” or as it is called “world space”.

Now lets move it!
After that you have declared what direction your object is going you multiply it with some sort of “speed”. like 1.5f and then add it to the position.

like the code LeftyRighty wrote above.

frog.position += Vector3.right * 1.5f;

by using that code you calculate a new value saying "it should go in the direction right (from the objects own point-of-view) by a speed of 1.5f then lets add it (+=) to the frogs current position (frog.position)

Just use Translate…

var frog : Transform;


function Update() {

if(Input.GetKeyDown("up")) 
    frog.Translate(Vector3.forward * 1.5f);
  
}