I only have a little bit of code experience from before, so my code is far from good and even further away from perfect… Don’t expect anything more than terrifying pile of letters!
But anyhows, I ran in to a problem with transform.Translate and feeding it with changing variable (I have no idea what is causing the problem).
var player_currentSpeed = 0; //currentSpeed used with .Translate
var player_targetSpeed = 15; //later on will be properly controlled
var player_acceleration = 0.1; //how much the ship is accelerated per cycle
var player_accelerationDelay = 0.25; //delay in acceleration cycle
var player_accelerationNext = 0; //this + Time.time will update 'next cycle'
function Update ()
{
//propel ship forward via transform.Translate on X.0.0
transform.Translate(player_currentSpeed * Time.deltaTime,0,0);
// check if current speed is lower than target speed, and that enough time (acceleration delay) has passed, if so, increase speed. else do nothing
if(player_currentSpeed > player_targetSpeed Time.time < player_accelerationNext)
{
//determine accelerated speed in cycle
player_currentSpeed = player_currentSpeed + player_acceleration;
//determine time of next acceleration cycle
player_accelerationNext = Time.time + player_accelerationDelay;
}
}
if I remove the whole ‘increase speed’ part (where Time.time is checked against the next time to do increase) and change player_currentSpeed to XX then the script works. But the increasing itself doesn’t and I have no idea why. Of course I could do another script that would run in the background and occasionally tell this script that the player_currentSpeed has changed, but I’d rather have this script perform all the forward moving of the ship… and this dead end is above my skills :<
I don’t wish a code rewrite, I want to do it myself as I get better, but I want to fix this one so I can start making new scripts to improve my skills… you see… I want to implement all features first as very rought script, then as I progress, I’ll rewrite them better and better till they shine like a rising star ![]()
Cheers to Community and Unity!