Ok so i am making a script for a tank and for some reason it can rotate but it wont move forward or back ward heres my script someone please help thanks
var forwardSpeed = 1.0;
var backSpeed = -1.0;
var rightSpeed = 1.0;
var leftSpeed = -1.0;
function Update ()
{
amtToMove = rightSpeed * Time.deltaTime;
amtToMove1 = leftSpeed * Time.deltaTime;
amtToMove2 = forwardSpeed * Time.deltaTime;
amtToMove3 = backSpeed * Time.deltaTime;
if (Input.GetButton(“f”))
{
transform.position(forwardSpeed* Time.deltaTime,0,0);
}
if (Input.GetButton(“s”))
{
transform.position(backSpeed* Time.deltaTime,0,0);
}
if (Input.GetButton(“d”))
{
transform.Rotate(0, rightSpeedTime.deltaTime,0);
}
if (Input.GetButton(“a”))
{
transform.Rotate(0, leftSpeedTime.deltaTime,0);
}
}
if (Input.GetButton("f"))
{
transform.Translate(forwardSpeed* Time.deltaTime,0,0);
}
if (Input.GetButton("s"))
{
transform.Translate(backSpeed* Time.deltaTime,0,0);
}
setting position sets an absolute place in the world. Calling Translate will move x amount from its current position.
For moving forward try “transform.Translate(Vector3.forward * forwardSpeed * Time.deltaTime))” and backward try “transform.Translate(Vector3.forward * -1 * backSpeed * Time.deltaTime))”
Oh, someone posted while I was writing
You need to understand basic datatypes, Mr.B.
Functions and variables can be the members of objects. Imagine members as properties of that object. Functions(Methods/procedures, whatever you want to call them) are different from member variables in the fact that functions are chunks of code with arguments that are referenced by name. These can be set, but are more often called. Variables, on the other hand, are merely locations for data. Depending on the primitive type, variables will store different types of data.
position is a member variable of the object Transform.
Translate() is a member function of the object Transform.
The reason you can’t really call Transform.position() is because it is not implicitly a function, it’s actually a reference to a struct, namely Vector3. Since Vector3 isn’t an object, it is a struct (something of a middle road between an object and a primitive type), what you typed was actually setting the position by creating a new vector. --This is due to some inconsistent behavior on the part of Structs these days, and omission of the new keyword. (I myself, personally don’t like Vector3 as being a Struct)
This kind of problem would not have arisen for you if you would just take the time to understand core programming concepts, any beginner’s syntax reference would teach.
lol TerXlll you are following me but thanks for the info. I do take some time to try to learn the basics but I don’t have that much time to learn because of school and homework, all that stuff.
Well, this was a fair question. I wanted to make good on my offer to help if you needed explanation of why something didn’t work.