This throws an error, im trying to work out teh distance between two points, and if its less than 50, do something, but its not liking the type of the var:playerDistanceFromSpawn. Any ideas?
playerDistanceFromSpawn = Vector3.Distance(spawnPos, playerPos);
if (playerDistanceFromSpawn < 50){
Disclaimer: I play in C# land, but this should work:
playerDistanceFromSpawn = Vector3.Distance(spawnPos, playerPos);
if (playerDistanceFromSpawn < 50.0f){
It should work even without the .0f…
I think you are getting errors because the types of variables you provided are incorrect or are not set up at all
What’s the error you are receiving?
In the mean while, double check the declarations:
var playerDistanceFromSpawn: float;
var spawnPos: Vector3;
var playerPos: Vector3;
if you didn’t add the types and maybe declared them like:
var spawnPos;
you might assign wrong types into them and not receive an error from the compiler. (For example a Vector3 instead of a float, or even a string instead of a float).
The compiler will have no way of knowing (for example) that it’s not right to assing Vector(1,1,1) into playerDistanceFromSpawn.
The first time it will assign a value to it, Javascript will guess that playerDistanceFromSpawn is probably a Vector3, and will define it that way. Then, when you reach your line, obviously you cannot assign a float into a Vector3 and you receive an error.