Trying to make a charge attack in my game. My character only moves forward by 1 unit.
I'm designing a pokemon inspired game where different pokemon have different attacks that can all be called upon by the same script. One of my attacks, tackle, is supposed to make the character run forward for a few seconds and do damage to anyone they collide with, similar to Reinhardt's charge attack in Overwatch. Whenever I press the attack key ('V') my character moves forward by one unit instead of moving continuously over a period of time. My attack script looks like this: public class MyPokemon : MonoBehaviour { public BasePokemon basePokemon; void Update () { GetComponent<Renderer>().material = basePokemon.material; if (Input.GetKeyDown(KeyCode.V)){ basePokemon.abilities[0].Cast(); } } }
and my Tackle code looks like this: public class Tackle : Ability { public override void Cast(){ float duration = 30; float speed = 5; float currentTime = duration; GameObject pokemon = GameObject.Find("Pokemon"); name = "Tackle"; damage = 5; if(currentTime > 0){ pokemon.transform.Translate(Vector3.forward * (Time.deltaTime * speed)); currentTime -= Time.deltaTime; } Debug.Log(currentTime); } }
Thanks!
Your answer
Follow this Question
Related Questions
Timer-Based Attack System 0 Answers
transform.Translate() effect is being reverted 0 Answers
problem with trigger location 0 Answers
Copying variables in game? 0 Answers
Visualise Physics2D.BoxCastAll 1 Answer