math,unity3d,numbers , Convert a large int to a float between 0.0f and 1.0f


Convert a large int to a float between 0.0f and 1.0f

Question:

Tag: math,unity3d,numbers

I'm working on a project where I have a pane that goes from 0 to 500 on the x and z, but I need to convert that coordinate (from 0 to 500) to a float in the range of 0.0 to 1.0 in because it is required from some of the functions I'm using.

I'm stuck on how to take the axis position (lets say something like, 3475x3475) and change in into it's relative position on the plane from 0.0f to 1.0f

(I've tried to write this in a way that any programmer can understand, instead of using Unity terminology. If you're a Unity programmer and would better understand it with that terminology tell me and I'll re-write it)


Answer:

You can take your number that ranges from 0 to 500 and simply divide it by 500, e.g. scaled_x = x / 500.0f. Depending on the language and the type of x you will need to divide by either 500 or 500.0f. If you are using a language that has integer division like C, and if x is an integer than x / 500 will be zero unless x is 500, but if you do x/500.0f than you will get a float between 0.0f and 1.0f (assuming x is between 0 and 500 inclusively). This is of course assuming you want a linear mapping, e.g. 0 maps to 0, 100 maps to 0.2, 250 maps to 0.5 and so on.


Related:


How to draw each a vertex of a mesh as a circle


ios,unity3d,shader,mesh,particle
How to draw each a vertex of a mesh as a circle?

How to Create Thumbnails in unity


unity3d
I am creating a video player app for android. for that i need to create thumbnails for the videos present in the videos folder. After searching web i could able to understand unity's MovieTexture doesn't support for android. This one i could able to solve using a plugin. For creating...

Turning an avatar into a 3rd person character


animation,unity3d
I just learned how easy it is to simply drag a 3rd person character controller prefab (from Unity's standard assets package) and drop it into the hierarchy. Using the WSAD and Space keys feels pretty natural, so I wondered if I could apply the same character controller to a customized...

Matlab: Writing to a file


arrays,matlab,loops,math,for-loop
I want to store mean_2....mean_8, std_2....std_8, and coVariance as separate columns in a file. Help Please? This Code calculates IntervalFeatures of Erp signal with 256 time frames and plots them Datapoints are store in A ___________HowTheCodeWorks________________________________________________ each 1x4 sliding sub-matrix is made a column for eg:- if A is...

Solving a complex recurrence relation for the Traveling Salesman


algorithm,math,time-complexity,computer-science,recurrence-relation
I need to solve the exact time complexity for the brute force version of the Traveling Salesman using a recurrence relation. I've worked out the recurrence relation to be as follows: T(n)=T(n-1)*(n-1)+1 But I'm having trouble reducing that that to a closed form of the function, and thus get the...

Rotate line segment with Button


math,javafx,geometry,coordinates
I have a line which has points (x1,y1) and (x2,y2). I wanted to attach a Button to it, it should align with the line by rotating based on the line segment points. I need some help in calculating the rotation angle for the Button.

Separating axis theorem: rotation around center of mass


c++,math,rotation,rotational-matrices,separating-axis-theorem
The problem is in Polygon::FindAxisLeastPenetration: double Polygon::FindAxisLeastPenetration(unsigned int *faceIndex, const Polygon &polygonA, const Polygon &polygonB) const { double bestDistance = -std::numeric_limits<double>::infinity(); unsigned int bestIndex; for (unsigned int i = 0; i < polygonA.points.size(); i++) { Vector2D n = polygonA.normals[i]; Vector2D nw = polygonA.rotationMatrix * n; //ROTATION Matrix22 buT = polygonB.rotationMatrix.Transposed();...

How to get rid of scale factor from CORDIC


math,vhdl,fpga,rtl,cordic
From CORDIC, K_i = cos(tan^-1(2^i)). As I know the K is approached 0.607xxx. How do I approach to 0.607xxx? Also does it mean that I can use 0.607xxx instead of cos(tan^-1(2^I))? I am citing from this article. I am trying to implement hyperbolic tanh function. And so far I understand...

Issues With length() And Multiples Of 3


java,math,multiplication,string-length
Lets see if someone can wrap their head around this: if you get the length of a String using length(), the String always being multiples of 3,(in my case: "1.02.03.04.05.06.07.0 etc.") each 3 characters representing a letter, with .1 indicating a capitol letter, how do you use the length to...

Reverse ^ operator for decryption


c,algorithm,security,math,encryption
I'm trying to reverse the following code in order to provide a function which takes the buffer and decrypts it. void crypt_buffer(unsigned char *buffer, size_t size, char *key) { size_t i; int j; j = 0; for(i = 0; i < size; i++) { if(j >= KEY_SIZE) j = 0;...

How expensive is creating class instance? (performance considerations) [closed]


c#,unity3d
In C#, how expensive it is to create new class instance? I'm speaking in context of using C# in unity3d. Meaning that stuff continuously gets called many times per second. In C++, generally speaking (while making games) you may want to reuse anything you created with new/smart pointers, you would...

Create array/list of many objects(initially unknown amount) by tag


c#,arrays,list,unity3d,gameobject
I'm currently working on a radar system for my space game, and I am trying to work out how to add gameobjects, by tag, to either a list or array that can then be used in other methods. I can't do this manually because I will be procedurally generating each...

EditorGUILayout.Popup option is not changing


unity3d,unity3d-gui,unity3d-editor
using this simple code I'm showing a dropdown int selected = 0; ///* string[] options = new string[] { "Start With", "End With", "Contains", }; //criteria = EditorGUILayout.Popup("Search Criteria", 2, options); //*/ criteria = EditorGUILayout.Popup("Awesome Drop down:", selected, options, EditorStyles.popup); it showing dropdown with option perfectly but the problem is...

why when i change slaying in the last else statment it crashes the browser


javascript,arrays,math
i was playing around in code academy and for some reason when i change the last slaying i the else statement to true instead of making the person invincible it just crashes my browser any ideas why thank you in advance var slaying = true; var youHit = Math.floor(Math.random()*2); var...

Calculate The object angle(face) having two points? [closed]


c++,math,geometry,angle
C++, I want calculate the angle of the direction of the two points. Here is a picture which shows the two points and the direction of how to get the angle of the direction? p1 - start point. p2 - direction point. me need direction angle(facing?) from p1 to p2...

Excel log equivilent to JS Math.log()


javascript,excel,math
In my javascript code I have the following Math.log(20) = 2.995732273553991 In my excel formula I try to replicate this with =LOG(20) = 1.301029996 Anyone have any idea why I'm getting two different outcomes? I'd like my excel to match my js. ...

3 X 3 magic square recursively


c++,algorithm,math,recursion
I'm trying to find all possible solutions to the 3X3 magic square. There should be exactly 8 solutions. My code gets them all but there are a lot of repeats. I'm having a hard time tracking the recursive steps to see why I'm getting all the repeats. // This program...

Removing a prior sample while using Welford's method for computing single pass variance


algorithm,math,statistics,variance,standard-deviation
I'm successfully using Welford's method to compute running variance and standard deviation as described many times on Stack Overflow and John D Cook's excellent blog post. However in the stream of samples, sometimes I encounter a "rollback", or "remove sample" order, meaning that a previous sample is no longer valid...

Matlab: For loop with window array


arrays,matlab,math,for-loop,while-loop
This is my one dimensional array A, containing 10 numbers: A = [-8.92100000000000 10.6100000000000 1.33300000000000 ... -2.57400000000000 -4.52700000000000 9.63300000000000 ... 4.26200000000000 16.9580000000000 8.16900000000000 4.75100000000000]; I want the loop to go through like this; (calculating mean interval wise) - Interval length of 2,4,8 (a(1)+a(2))/2 - value stored in one block of...

How do I Mute The Audio In Unity 3D?


c#,audio,unity3d,mute
with script this. what is wrong in script this ? audio.mute = ToggleButton.isSpeakerOff; sorry bad english,fast answer please correct my script please...

Unity procedural TileMap generation without creating gameobject per tile


unity3d
I've been searching all over the internet to find a efficient way to create procedural tilemap without creating a gameobject per each tile. There is none, or simply i couldn't find it, because i really don't know how to make a search for it. All the TileMap tutorials i found...

Formatting large numbers in C#


c#,.net,unity3d,formatting
I am using Unity to make an "Incremental Game" also known as an "Idle Game" and I am trying to format large numbers. For example, when gold gets to say 1000 or more, it will display as Gold: 1k instead of Gold: 1000. using UnityEngine; using System.Collections; public class Click...

What is this programming method called? And is it bad?


c#,unity3d,modular
Lately in my Unity projects, I have discovered that to create a more modular application it helps to have a static List in a class that contains references to all or some of the objects created so that they may be accessed easily from other parts of the program. An...

How to calculate a random point inside a cube


math,vector,3d,cube
I'm trying to figure out the math to find a random point inside a cube. I have something small but it can't take into account the rotation of the cube. Here are some images of my results. Here you can see the cube is rotated to some degree but when...

var keyword vs actual type? [duplicate]


c#,unity3d
This question already has an answer here: Use of var keyword in C# 86 answers I'm using vim + omnisharp/syntastic for some unity3d development in C#. When I declare a variable using the actual type, for instance string[] myArray = new string[5]; I get a warning message telling me...

Manual slide-in animation using delta time


c#,animation,unity3d
I'm creating a simple slide-in animation for my game. The box is shown at the bottom with character dialog. The animation is supposed to look as follows: A square slides in from the left, then waits a bit, then expands to its full width. The box is made using Unity's...

implement pow in java without using math lib


java,math
I did a code like this: public static double myPow(double x, int n){ if(n==0) return 1; double t = myPow(x, n/2); if(n % 2 != 0){ if(n < 0){ return (1 / t * t * x); } else { return t * t * x; } } else {...

SWF works locally but not loaded from server


mod-rewrite,unity3d,swf,swfobject
Here is the deal. I have SWF build with Unity and embedded into HTML page with swfobject. It works perfectly well when I load page locally (zip), but it always says "Movie not loaded" when I try to load page. from server I have already inspect similar embedded movies (this...

Visually midway between two points on a x axis log scale [closed]


matlab,math
The follow plot shows my question: I would like to add a line between the points of 1e-1 and 1e-2. So I thought just (1e-1+1e-2)/2. But for a log scale that is not "midway". How can I calculate the "visual" midway value between these, or any two points in this...

Ranking with time weighting


python,algorithm,sorting,math
I am looking for a basic algorithm that gives more weigh to the recent reviews. So, the output value of the algorithm is mutable. For example, two reviews with exactly the same score, will have a different ranking based on the timestamp of the creation. Review_1 Score 10 creation 10/5/2014...

How can we use cordic to tanh(x+1)/tanh(x)?


math,cordic
How can we use cordic to tanh(x+1)/tanh(x) I can't get a idea about how to apply cordic to above function. In other word, which point on the above function, can we apply cordic?...

2D game development with Unity3D


unity3d,2d-games
I tried to find some answers to a few questions I have about Unity3D games development. I want to create 2D mobile games. The thing I really want to know is if I can create a mobile game for different platforms at one time (as cordova can build Android /...

Converting from Pixel Coordinates to UI Coordinates in Unity


user-interface,unity3d
Does anyone know how to convert from Pixel Coordinates to UI Coordinates and vice-versa in Unity? Let's say for example I want to click somewhere on the screen with the mouse, and a UI Image to be at that click position. If I do this won't work: Image img =...

LinkedHashSet and subList, getting n of collection


java,math,set,linkedhashset
I am trying to do a homework in math which is find a subset of collection {1,2,..,n} where n is a number given in the code, I cannot get it done with the sublist so I need to get your help with a math programming. For example for n =...

How to calculate the number of all possible combinations for a range of numbers from 1 to N?


python,math,combinations,itertools
Other than doing this: from itertools import combinations def brute_force(x): for l in range (1,len(x)+1): for f in list(combinations(range(0,len(x)),l)): yield f x = range(1,18) len(list(brute_force(x))) [out]: 131071 How could I mathematically calculate the number of all possible combinations? Is there a way to do it computationally without enumerating the possible...

Unity3D Bullet Tracers


unity3d,unityscript,raycasting
I'm currently working on implementing the elusive bullet tracer to my FPS. It isn't going so well. a. The tracers align themselves off of the barrel of the Raycast area b. They all aim themselves in the same direction, no matter where I point my cursor This is the formula...

Android - Unity3D freeze in splash screen on some phones


android,unity3d,screen,freeze,splash
I have a problem with Unity3D. I created a game with Unity 4.6.2f1. My problem is, game crashes after splash screen(Like trying to open itself constantly). The weird part is, game works on my phones and my tablets perfectly. I have Nexus 5(With Android 5.1.1) , Iocean X7S(With Android 4.2.2)...

Unity 3D Text becomes Word Cubes


android,unity3d,vuforia
As the image shows, my 3D Text keeps disappearing from my scene when I click Play, and then when I zoom in, this is what I see. When I exit the Play scene, it stays like that till I Ctrl+S and Save on which is returns to its proper text...

AdColony's OnVideoFinished not call in Android


c#,android,unity3d,adcolony
I have a problem with AdColony-UnitySDK. When AdColony's video is finish playing, OnVideoFinished() method don't be called. In this case, the following sources work well in iOS. And also, the server receive the success callback both device. So, only Android device that is not work. Here is the source code,...

How to get a pizza program to round to a full pizza In PYTHON [duplicate]


python,math,rounding
This question already has an answer here: How do you round UP a number in Python? 9 answers Python round up integer to next hundred 6 answers so i'm making a pizza program in Python 3.3 that takes input from the user and prints the amount of pizza's needed....

I'm trying to reduce the Length of this Code


c#,unity3d
I wrote some code today. I can't figure out how to reduce the length of this code, although it seems repetitive, every part is different. try { totalVerts.Add(verts[i]); if (verts[i].x > maxXvert) { maxXvert = verts[i].x; } if (verts[i].x < minXvert) { minXvert = verts[i].x; } if (verts[i].y > maxYvert)...

Have I properly sorted these runtimes in order of growth?


math,big-o,time-complexity,asymptotic-complexity
I am doing this small task which I have to arrange asymptotic runtime in ascending order. Here are the runtimes: Here is the order I believe they should go in: log10(n^4), n^3, 2^((log4n)), 2^(100n), e^pi^4096, n! + 12^1000 Is this correct? Or are there any errors? Thanks!...

randint() unexpected behavior


python,math
I'm writing a python script to find out some things about randomization. I have the following code: from random import randint one = 0 two = 0 olddiff = 0 diff = 0 sumdiff = 0 avgdiff = 0 headcounter = 0 counter = 0 while (headcounter < 500000): while...

Unity An object reference is required to access non-static member C#


c#,unity3d
Im trying to learn C# with Unity engine But a basic script like this: using UnityEngine; using System.Collections; public class scriptBall : MonoBehaviour { // Use this for initialization void Start () { Rigidbody.AddForce(0,1000f,0); } // Update is called once per frame void Update () { } } gives this...

Unity 5 Audio Volume Slider (Solved)


c#,audio,unity3d
I am trying to create an slider that I can use for volume control in Unity 5 but the volume will not change. My Game Objects are called MainMusicPlayer for the audio source and Volume Slider for the slider I am going to post the whole script as it would...

Csproj file in unity changes everytime i reload the project


c#,unity3d,msbuildcommunitytasks
I want to change the 'csproj' file of my unity project in order to be able to access a specific library as this answer sugests. I am manually editing the file but every time i reload the project, the 'csproj' file returns to it's initial state. Is this a common...

Math operations within HTML


html,math
Is it possible to perform math operations within HTML, like <div width="50/2">? Or can this only be done using Javascript or CSS?

Loading MP3 files at runtime in unity


c#,unity3d
I'm trying to load an mp3 file at runtime using the WWW class that is provided in Unity. I don't get any errors, but I'm unable to play the music after the song has been processed. I have looked everywhere and cannot find anything to help me. Here is the...

how to add Scoring to unity3D 2d top down car game?


unity3d,2d,car,topdown
I'm making 2D top down car game. as for now car game working with if player car hit enemy car game is over. I used for it adding tag to Enemy car and if player car collision detect enemy car with tag the finish the game. My question is: How...

Bash script for basic mathematic operations


linux,bash,math
I am new to Linux, and I just want a Bash Script to do basic arithmetic operation to a text file 1 2 3 4 and the results should be addition and multiplication in separate text files say add + 5 for 1st text file and mult * 5 in...