Do you remember old "Arcade Volley" videogame? A.I. Logic for opponent?

Hello!
I’d like to make a simple “Arcade Volley” Like game. I was wondering what’s the “logic” in the opponent script. You know … following the ball, hitting (forward or backwards?) when to jump …

how would you do a script for the enemy? I don’t mean the code, (right now) …

you can calculate precisely where the ball is going to fall using physics formulas.

Vertical movement uses formula for accelerated movement, and horizontal movement is linear.
So just move the opponent to that point and here you go.

… so for the X axis I can “follow” the ball’s X axis … but I am too dumb to use that formula … I think!

It would be difficult to know if opponent should hit the ball forward or backward (using a bounce with the wall to send the ball to the other side of the field!)

Hello! And Sorry again … How can I know what point on the X axis the ball is going to fall? It’s important to me so I can calculate an “offset” to put the player a little behind the ball … I am using something like:

``````        if (inFront) { offsetPalla = -0.6f; } if (!inFront) { offsetPalla = 0.6f; }
``````

But it’s in a fixed update, so my opponent seem to have Parkinson’s disease!!

The ball has velocity and the scene has gravity.

Using velocity, initial ball height solve vertical movement for time.

y1 = startPos.y + startVelocity.y * t - gravity * t * t / 2.

Solve this for t. Then you’ll know how long the ball will stay airborne.
This is school level formula for accelerated movement.
https://www.schoolphysics.co.uk/age14-16/Mechanics/Motion/text/Equations_of_motion/index.html

Now, here’s the fun stuff. Gravity does not affect horizontal movement. So you have

x1 = startPos.x + startVelocity.x * t;

And that’s it. Use t you’ve just foun and you’ll know where it is going to land.

1 Like

You could just try and match the x position of the ball, with a stay in the middle offset depending on the balls height (to allow for back wall bounce) and if it is over the other side of the net.

Sounds like you are setting a position of something in fixed update, probably directly via the transform. Dont do that.

Regarding the rest: Take a look at what @neginfinity wrote as thats everything you need to know

1 Like