sorry for the topic, i don’t now how to write it more clearly…
question is simple:
var Speed :int = 10;
OR
var Speed:int=10f;
what is the difference?
I have my player with max speed 10 (using standard motor script)
and my enemy ( a rabbit ) with max speed of 9.8
and it is moving by
Vector3.MoveTowards(transform.position, new_checkpoint, Time.deltaTime * 9.8);
but the rabbit is really more fast than me … what’s wrong, in your opinion?
do you know, where i must work to make the rabbit move A LITTLE less faster than me?
So as “F” stands for float, and float are numbers behind the point or comma, depends where you live.
If you want your rabbit to move faster, you change “10f;” to “11f;” and so on.
var gravity : float = 9.8f actually consists of two operations. First the literal value 9.8 is created, and then it is assigned to the variable. Problem is any floating point literal value is created as a double by default, and then guess what it won’t fit into a float (it doesn’t matter how big the value is, it’s all about how many bytes of storage). So to persuade the compiler to actually create the literal as a float you put the f after it, and then it can be assigned to the variable.
the reason for the “f” is to donate its “type”. the poblem is that there are multiple types of floating point numbers.
Single or often called float is a floating point number with 32bit
Double is 64 bit and
Decimal is 128 bit
to distinguis between those types there have a sufix
float = f
double = d
decimal = m
if you write a floating point numberr in code with out the suffix it is assumed to be of type double at least in c#
No, it depends on the language. This topic seems to talking about Unityscript, in which case floating point literals are created as floats by default. In order to use doubles, you need to specify “d”, as in “var foo = 123.123d”. C# is the opposite; double is the default and you need to add “f” to get floats. Using “f” in Unityscript doesn’t actually do anything; 1.23 and 1.23f are the same thing.