quick Help Wanted please

Hi there quick question
is this frame rate independent :
void Move(){
float moveInputX=movedirection.x;

float targetspeed= moveInputX *movespeed;//wanted topspeeed

float speedDiff= targetspeed -myRigidbody.velocity.x;

float accelRate =(Mathf.Abs (targetspeed) > 0.01f)? acceleration : decceleration;

float movement=Mathf.Pow(Mathf.Abs(speedDiff) *accelRate,velPower) *Mathf.Sign(speedDiff);

myRigidbody.AddForce(Vector2.right*movement);
}

also can someone help with the accelrate line i dont really understand the shorthand if statement
(bold and underlined) with the ? operator, perhaps if i had the longer version to compare to

I see nothing to do with time in there so I can’t imagine how it would know anything about time.

That’s called the ternary operator. Some swear by it, some hate it. It has a place but it can ALWAYS be written more clearly if you simply use an if statement.

THIS:

result = a ? b : c;

Is simply shortcut for:

if (a)
{
  result = b;
}
else
{
  result = c;
}

That’s it. “Ask if a is true, use b if so, otherwise use c.” It’s that simple. Google up ternary operator.

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

You may edit your post above.

If you have more than one or two dots (.) in a single statement, you’re just being mean to yourself.

How to break down hairy lines of code:

http://plbm.com/?p=248

Break it up, practice social distancing in your code, one thing per line please.

thanks mate that explanation was exactly what i was looking for.
im new here and the links were very helpful, ill make my code more readable in the future
thanks a lot

1 Like