solution found by using an external loop to be the counter for length of time that you can glide and increase the number of flaps
adding time to int
hi i am trying to make a semi-realistic bird flight code, but i am having an issue where when i try to add an int value of the time to the available wing flaps after the first initial period it instantly increases by each part of a second instead of the 2 seconds it should be, simpler it is meant to add 1 to flaps for every 2 seconds you are gliding instead after the first 2 seconds it just increases almost instantly. Here is the code. if this can be done easier using javascript please say so and give an example, still learning c# and haven't started with javascript, i have prior knowledge of software coding from software development classes, but that was using visual basic.
private Rigidbody rb;
public Text glidetime;
public Text flapnum;
public Text StateCheck;
public bool grounded = true;
public float timePressed = 0f;
public float currentTime;
public float rest;
private int flaps;
private int flaps2;
private int flaps3;
void Start()
{
rb = GetComponent<Rigidbody>();
flaps = 10;
setflaptext();
setglidetext();
}
void Update()
{
glideTimer();
glide();
fly();
flaps3 = flaps;
if (!grounded && rb.velocity.y == 0)
{
grounded = true;
StateCheck.text = rb.velocity.y.ToString();
}
if (Input.GetButtonDown("Jump") && grounded == true)
{
rb.velocity += new Vector3(0.0f, 20.0f, 0.0f);
grounded = false;
StateCheck.text = rb.velocity.y.ToString();
}
//if (Input.GetButton("Fire1"))
//{
// flaps =
//}
}
void FixedUpdate()
{
}
// glidetimer is used to check the length of the time gliding and increase the number of flaps by a set variable
void glideTimer()
{
if (grounded == false)
{
if (Input.GetButton("Fire1") && timePressed < 10)
{
timePressed += Time.deltaTime;
currentTime = timePressed;
rest = (int)currentTime;
flaps = flaps3 + (int)currentTime / 2;
setglidetext();
setflaptext();
}
}
}
// glide is the physics of the glide control
void glide()
{
if (Input.GetButton("Fire1") && grounded == false)
{
rb.drag = 15;
}
if (Input.GetButtonUp("Fire1"))
{
rb.drag = 0;
}
}
void fly()
{
if (flaps > 0)
{
if (Input.GetButtonDown("Jump") && grounded == false)
{
rb.velocity += new Vector3(0.0f, 10.0f, 0.0f);
flaps = flaps - 1;
flaps2 = flaps;
timePressed = 0;
currentTime = 0;
setflaptext();
setglidetext();
}
else if (flaps > 10)
{
flaps = 10;
}
}
}
void setflaptext()
{
flapnum.text = "Flaps: " + flaps.ToString();
}
void setglidetext()
{
glidetime.text = "Glide time: " + currentTime.ToString();
}
Follow this Question
Related Questions
How can I compare transform.position now and transform.position after 2 seconds? 2 Answers
few buttondown in fixed time 1 Answer
Suspension of Physics 1 Answer
Get position of object that uses Perlin Noise X distance/time back/offset? 0 Answers
Change scene after event (time or clicking on object) 0 Answers