2D Melee with knockback based on the "OverlapCircleAll" function
Hey, I want to make my ball get a knockback if I hit it. My stuff so far:
void Update()
{
if (timeBtwAttack <= 0)
{
//you can attack
if (Input.GetMouseButtonDown(0))
{
Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(attackPos.position, attackRange, whatIsEnemies);
for (int i = 0; i < enemiesToDamage.Length; i++)
{
enemiesToDamage[i].GetComponent<Ball>().TakeDamage(damage);
}
timeBtwAttack = startTimeAttack;
}
}
else
{
timeBtwAttack -= Time.deltaTime;
}`
Now I want that the ball I hit goes to the over site... I want that 2 player play against each other and everybody has to hit in the correct moment to throw the ball back... Like a pong game but everyone has to hit the ball in the right way.
I hope anyone can help me...
Floryus
Answer by streeetwalker · Apr 02, 2020 at 05:43 PM
Hey @Floryus, I'm trying to understand your question.
i see your code does some damage to objects that fall within your circle by accessing a script named Ball on each enemy, but nothing moving anywhere, and no indication of any ball object that is supposed to move.
You'll have to explain what the ball is (is each enemy a ball, and that is why you have script on the enemy name Ball?), and the situation of your objects set up in more detail.