I’m attempting to make a grid-based first-person dungeon crawler setup a la Wizardry or Might Magic. I need the player object to move forward 4 units over a given amount of time (probably 1 second) every time the up arrow key is pressed, and it’s returning very weird errors.
If I can get this working for forward movement, rotational movement shouldn’t be too hard.
Walls can be calculated with a child object talking to a global variable in the script, so I’m not too concerned about that.
The isMoving variable is to make sure that the player can’t force the player object to move off the grid. The “Up” button has already been declared in input properties so that isn’t it.
var isMoving = false;
var speed = 10.0;
function Start () {
}
function Update () {
if (Input.GetButtonDown("Up") isMoving == false){
isMoving = true;
transform.position = Vector3.Lerp ((transform.position.x, transform.position.y, transform.position.z), (transform.position.x, transform.position.y, transform.position.z + 4), speed * Time.deltaTime);
isMoving = false;
}
}
This is returning various errors, including not expecting commas and expecting semicolons at the end of each transform.position.letter statement.
To my understanding, the transform.position.letter statement declares the current position along that axis and is as good as an integer for this sort of thing. The API reference guide seems to think so anyway.
I have also attempted it in a manner suggested for similar problems elsewhere (using variables to declare the vector3):
var isMoving = false;
var speed = 10.0;
var startPosition : Vector3(transform.position.x, transform.position.y, transform.position.z);
var endPosition : Vector3(transform.position.x, transform.position.y, transform.position.z + 4);
function Start () {
}
function Update () {
if (Input.GetButtonDown("Up") isMoving == false){
isMoving = true;
transform.position = Vector3.Lerp (startPosition, endPosition, speed * Time.deltaTime);
isMoving = false;
}
}
It returns similar errors.
I’m a newbie at coding but this seems like it really should work. Anyone know what’s wrong with it?
Unity version 3.53f3