Hello, I’m currently making a table tennis game for the htc vive.
I’m currently working on the ai but I ran into a slight problem. It’s a very simple ai and I’m pretty frustrated that I cannot figure it out.
The idea is to have the AI paddle follow the ball (the ball is an actor blueprint) along its Y and Z values. So essentially, the paddle will only move up, down, left, and right.
I’m having difficulties finding the right way of doing this. It seems that I am not getting the location of the ball_bp correctly, I’m not breaking it correctly, or I’m doing something wrong entirely.
I’ll post a screenshot of what I have so far.
The get all actors of class is not being used? There is nothing connected to the input execution pin.
Also you have the ball_bp variable set already, so why get all actors of class when you could just use a get ball_bp and get its location directly?
~
Yeah I was just tinkering around. I tried a while ago to simply use get all actors of class but it doesn’t seem to work. I executed it with event tick and then drug the output exec to set actor location. That didn’t work either.
christianled59,
I’m a total newb with UE4 (only been working on it for less than a year) so what I’m about to say is likely wrong. Bu~t just lookin’ at your BP there’s something that kinda seems strange to me.
Unless you’re drunk, and lookin’ to play crazy pp with a friend or 10, I don’t really see why you’d want to look for the avg. location of multiple balls.
Jokes aside, lookin’ up on that get actor average array node, it seems like that’ll get you the average location of all the actors in the class. Maybe since there’s only 1 it’s freakin’ out. (Ideally it should still work, but technically there’s nothing to average if there’s only one.)
Is there a reason why you don’t just cast straight to the ball_BP, pull out its static mesh (for the ball) and GetWorldLocation on that? Also, for the paddle
maybe just set and GetWorldLocation on its static mesh (the paddle) as well?
I’ve tried casting. I think I may have just figured it out. I used get all actors and then used a "get function of off the array, then targeted the ball (static mesh), got world location and hooked it up.
The reason I can’t just simply get world location of the paddle is because I need the paddle to gradually move to the ball. It can’t just instantly move there.
Okay, it’s not quite working yet. I have managed to get the paddle to move towards the ball, but now I need to make it where it only moves along the y and z axis. I have no earthly clue how to do that. Break vectors do not seem to work.
Sorry for the spam. I’m trying a physics constraint. I’ll see how that goes.
Okay, so I have managed to get the paddle to move to the ball with a good speed and everything. Now I need to figure out how to lock the actor to the y and z axis. It seems a constraint does not work. Unless I’m doing it wrong.
I fixed it. I just had to get actors, target mesh, get location, and set the paddle location there with sweep toggled. I had to enable physics and lock the x axis and all rotation axis.