Question by
theswedishone · Apr 25, 2017 at 02:52 PM ·
velocitychargethrust
increase velocity/thrust with charged button
hey there i saw u help someone before with a charge button that would increase over time
my question is however,
i have a script that goes public float velocity = 2.5f; public float chargelevel = 2; public float chargespeed = 10f; public int chargelimit = 100;
// Use this for initialization
void Start () {
}
// Update is called once per frame
public Transform shootpos;
public GameObject cannonBall;
public Transform spawn;
public float thrust;
public float gravity;
public float fireRate = 0.5F;
private float nextFire = 0.0F;
void Update()
{
if (Input.GetButtonDown("Fire1") && chargelevel < chargelimit)
{
chargelevel += Time.deltaTime * chargespeed;
}
if (Input.GetButtonUp("Fire1"))
{
GameObject clone;
velocity = velocity * chargelevel;
nextFire = Time.time + fireRate;
clone = (GameObject)Instantiate(cannonBall, shootpos.position, shootpos.rotation);
clone.GetComponent<Rigidbody>().AddForce(spawn.forward* thrust);
clone.transform.position = transform.position;
GameObject.FindGameObjectWithTag("Cannon");
clone.rigidbody = transform.position * chargelevel;
chargelevel = 0;
}
}
} i have no idea how to impliment the charge level to increase velocity of the ball for a more stronger attack
would appreciate the help
Comment
Your answer
Follow this Question
Related Questions
3d space heading/volocity direction prediction and mp/s hud,code? 1 Answer
why is the rigidbody's velocity zero in OnCollisionEnter2D? 1 Answer
What are the parameters passed in vector2? 0 Answers
Vertical Velocity for fps 0 Answers
Slow down a character while they are midair while keeping their original velocity 0 Answers