How can I set the y position every frame update? (C#)
I'm currently making my first game without a tutorial, and am running into an annoyingly simple problem.
It's a racing game, and I have the translation across the x axis equal to the current rotation, so that if the car is angled to the left, it will continuously travel left. However, while this works really well, it also for some reason makes the car travel downwards, the steeper the car angle the faster down it goes.
I have no idea why this is happening, but to fix it I figured I could cheat and just set the y value to the car's original position every frame (the road is what travels down, the car is supposed to keep at the same y value). But when I try it by setting y to transform.position.y and saying y = -16, nothing happens.
I've been trying to fix this for hours but nothing works, and that's only my most recent attempt. If you have any ideas on how to keep the car from going slightly down whenever it turns, I would GREATLY appreciate it!
Answer by Codelyy · Jan 03, 2017 at 05:43 PM
Is Gravity being applied to the GameObject?
Also as UnityCoach said, some code samples would be helpful.
Answer by dpoly · Jan 03, 2017 at 11:15 PM
You should show the code. However the problem seems to be you're changing a local variable, not the transform itself. Try
car.transform.y = -16;
But you really should solve the original problem , not paper over it. Why not ask a question about that instead?