- Home /
2D Topdown Character Contoller
Hello :) First i'd like to clarify that im not even 18 and i just play around with Unity for fun. I really like game designing but i have no idea about programming (I mainly don't know what words to use in my code. I know about functions, variables etc.)
I am working on a little topdown 2D space shooter game and i want to make a controller script. I want it to be in Javascript because i don't really get the thing with the MonoBehaviour in C#. So i have a basic script where you move with WASD and there is a speed var, but i would like to have my character move only with W (And if possible, have it accelerate a bit slower and not have it reach 100% speed!) and follow the mouse cursor withing the game. So im gonna press W and it will follow the cursor and im gonna make a shootign script next)
Ok that's all. Here is the scipt i currently have. (It's not mine, i found it in a question here in answers.unity3d.com)
//Inspector Variables
var playerSpeed : float = 8; //speed player moves
function Update ()
{
MoveForward(); // Player Movement
// Generate a plane that intersects the transform's position with an upwards normal.
}
function MoveForward()
{
if(Input.GetKey("w"))//Press up arrow key to move forward on the Y AXIS
{
transform.Translate(0,playerSpeed * Time.deltaTime,0);
}
if(Input.GetKey("s"))//Press up arrow key to move forward on the Y AXIS
{
transform.Translate(0,-playerSpeed * Time.deltaTime,0);
}
if(Input.GetKey("a"))//Press up arrow key to move forward on the Y AXIS
{
transform.Translate(-playerSpeed * Time.deltaTime,0 ,0);
}
if(Input.GetKey("d"))//Press up arrow key to move forward on the Y AXIS
{
transform.Translate(playerSpeed * Time.deltaTime,0 ,0);
}
}
I noticed that it says if(Input.Get$$anonymous$$ey("w")) //Press UP ARROW the script had originally the arrow keys for the momevent. I changed it to WASD