# Creating a Pacman style game, would appreciate help.,My first real game, pac-man inspired. Appreciate help.

Hi everyone, so I am currently designing a Pacman inspired game, simply for its “simplicity”. The only thing is, I haven’t quite got the coding in the old noggin yet, going rough tutorials and getting there but it is a long battle.

My question is, I need a little kick start on a simple bit of code that makes the character, which is a sphere for now, move one unit to whichever key is pressed, and will continue to move if the key is held, otherwise he will stop. What I tried made the character just snap from one place to another instantly. Another thing I was considering is for the character to rotate to the directing he is moving, so turning 90 or 180 degrees as you press a different direction key. Btw, I am using and learning JavaScript.

Sorry to be a pain, I really want to start making something simple to begin with so that I can learn better by doing it without tutorials, but it seems that a little to unrealistic for my current level of programming knowledge.

Thanks for any help everyone, it means a lot!,

Here is a bit of code to get you started. It use the Horizontal and Vertical axes, which are assigned to the arrow keys and ASDW by default. The code points the ‘up’ of your model in the direction of movement. Adjust ‘moveDist’ and ‘speed’ in the inspector as needed for your game.

#pragma strict

var target : Vector3;
var moveDist = 0.1; // Amount to move
var speed = 0.1;     // Units moved per second

function Start() {
target = transform.position;
}

function Update() {

if (transform.position == target) {
var f = Input.GetAxis("Horizontal");
if (f != 0.0) {
var dir = Vector3.right * moveDist * Mathf.Sign(f);
target += dir;
transform.up = dir;  // Rotation
}
else {
f = Input.GetAxis("Vertical");

if (f != 0.0) {
dir = Vector3.up * moveDist * Mathf.Sign(f);
target += dir;
transform.up = dir;  // Rotation
}
}
}

transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
}