- Home /
object going sideways when a negative x value is given.
I'm following the Walker Boys tutorial and have so far made it to working with the transform commands. In it he me write this code:
var boxSpeed = 4.0;
function Update () {
transform.Translate(boxSpeed*Time.deltaTime,0,0);
As expected, the cube moved forward. But when I gave it a negative value (i.e. -4), instead of the cube going backwards like in the video, it went sideways. I checked and recheck his code with mine, they're identical as far as I can tell. This occurs on the y and z axis as well. Can anyone please explain why this is?
I don't use Translate but from the doc I'm surprised your example DOES move forward since it's addressing the X axis. Try adding Space.World as the last parameter in Translate, does that change things?
No, it made no change, though for whatever reason, it's changed it's behaiver since I posted this. Now it does go forward and back as intended, but it also moves to the side on another axis, even if all axis are zero. So even if it's supposed to stand still, it moves. The change occurred before I even tried your solution. Thank you for trying though.
I'm beginning to wonder if the Unity is broken for me becuase I'm encountering other strings of code that aren't behaving like they should. Even when copied exactly as what I see in forums, and videos. $$anonymous$$y results are different than theirs.
Try this is an empty scene and see if you encounter the same behaviour. It's probably something else you haven't considered.
It did infact work. I'll have to compare the old scene with the new scene to see what was change. I don't ever recall messing with anything at all but the scripting, I even created a fresh object and still got the misbehavier. Thank you very much for your help. Now that I think about it, it seems like an obviouse thing to try though. lol.
Answer by ERPM88 · Feb 17, 2014 at 12:38 AM
Try this is an empty scene and see if you encounter the same behaviour. It's probably something else you haven't considered. @Benproductions1
I'd much prefer if you asked me to convert my comment to an answer, but none the less thank you for cleaning after yourself unlike so many others in this community :)
Sorry, I'm new to Unity and thus the way things are done on the forums. But at least I made sure you got credit for the answer. :)
Yea, the general reason you want to have the answer written by the person who gave the answer, either a converted comment or a new answer, is that accepting their answer will give them karma and thus reward them for their answer. I don't really care, this is just for future reference ;)
The tutorial link is currently down, but if it ever comes back up you should watch it.
Your answer
Follow this Question
Related Questions
rigidbody.angularVelocity Negative Value? 1 Answer
Can be terrainData.setHeights' values negative? 1 Answer
Wrong positon 0 Answers
Inverse the mouse position value 2 Answers
Small value range from Input.GetAxis with XBox360 joystick 0 Answers