wanted to make sure that an object simulates the opening and closing of a parabola. These exercises I am trying to do is to learn how to integrate mathematics with the script. This is my script so far, but the result is always 1. Who can help me?
#pragma strict
var a : int = 2.0;
var b : int= 8.0;
var c: int =1.5;
var x : int;
var y : int;
function Start () {
x= -b/(2*a);
}
function Update () {
y = (a*x)*(a*x)+(b*x)+c;
print(y);
}
Well, all your variables are typed as ints. Ints are used for natural numbers 0,1,2,3… where-as you probably want them typed as floats, used for real numbers, 0.12345, -42.42, etc. As far as my schoolboy maths says, x=-2, so your calculation is basically y = 0 + c. Since c is an int, it’s been truncated from 1.5 (a real number) to 1 (a natural number). Hence y is 1.