- Home /
Verctor3 isnt updating with variables
var jumpPower = 8;
var rotationSpeed = 100;
var tuckSpeed = 1;
var runSet = 1;
private var speed : Vector3 = Vector3 (6, 0, 0) * runSet;
private var jump : Vector3 = Vector3 (0, 1, 0) * jumpPower;
Hi Guys,
In need of some help, for some reason my vector3s here arent taking the update values of runSet and jumpPower.
Do you have any idea why this is please?
Thanks!
[Edit by Berenger : Code Formatting]
That is that they use the values listed here, but when the game is running and those values change, the vector3 continues to use the origenal value ins$$anonymous$$d of the new ones.
Do you mean that when you change jumpPower=5
to jumpPower=8
the Inspector still shows 5? That's a feature. Anything you can see in the Inspector is meant to override declare values.
No, I mean that when the game is running, the values for runSet and jumpPower change. But when they do the value of each in these Vector3 declarations stay as they were on load up, ins$$anonymous$$d of using the updated values like they should - Ive got my game working by moving "Vector3 (0, 1, 0) * jumpPower;" into my function update, but that is pretty messy.
I'm going to leave the question up in-case someone knows why it wasn't working in the first place thought, i cant see any reason for it to not have been working...
Answer by Berenger · Mar 03, 2012 at 06:16 PM
speed and jump need to be recalculed in a function called every frame like Update. What you wrote, it's called only once.
Or if you only change runSet and jumpPower occasionally, you can also recalc speed and jump right then. But either way, assignments never "track" what they were based on an auto-update.
Thankyou for explaining that to me, I always assumed that if variables changed then the assignments would update too.
Thanks again for your help Berenger & Owen Reynolds!