Hello,
Whenever I try to use the code shown below to move up, it doesn’t add 0.005f to the X value of the object. Instead, it goes from it’s instantiated position (-0.055f) to -0.05486955. Why does this happen? I tried adding 0.0005f to the current location but it does the same… Thanks!
void Move() {
if (Input.GetKeyDown(KeyCode.UpArrow) && transform.position.y < 0.050f) {
transform.rotation = Quaternion.identity;
transform.Translate(0, 0.005f, 0);
}
}
,Hello,
If I want to move my character by adding 0.05f to it’s Y value, it behaves very weirdly.
The location of the object is currently -0.055, but when I run the game and press up, the location changes to a very weird and long value, and it hasn’t even added 0.05f. (-0.05369557). What is going on here?
This is the code:
void Move() {
if (Input.GetKeyDown(KeyCode.UpArrow) && transform.position.y < 0.050f) {
transform.rotation = Quaternion.identity;
transform.Translate(0, 0.05f, 0);
}
if (Input.GetKeyDown(KeyCode.DownArrow) && transform.position.y > -0.055f) {
transform.rotation = Quaternion.Euler(0, 0, 180f);
transform.Translate(0, 0.05f, 0);
}
if (Input.GetKeyDown(KeyCode.LeftArrow) && transform.position.x > -0.065f) {
transform.rotation = Quaternion.Euler(0, 0, 90f);
transform.Translate(0, 0.05f, 0);
}
if (Input.GetKeyDown(KeyCode.RightArrow) && transform.position.x < 0.065f) {
transform.rotation = Quaternion.Euler(0, 0, 270f);
transform.Translate(0, 0.05f, 0);
}
}