So I’m remaking the heli in my game R2DA.
What I want this to do is fly realistically along a path. But this time the path should be auto generated.
I’m not interested in the actual flying part, what I need is a pathfinder but for helicopters.
The heli will spawn 500 studs away from goal in a random direction, it should be able to auto generate a path from start to the goal without flying through buildings. The path can’t collide with objects but the heli is allowed to clip side of buildings aslong as the path isn’t going through them.
Are the buildings randomly generated? If not, I would highly suggest just hardcoding X paths, it will probably save you time that way.
If they are randomly generated, you can first generate a curve in 2D from a top-down perspective (at around half the height of those tallest skyscrapers) that doesn’t intersect any high buildings. Then after you have a 2D curve, you can interpolate the height downward over the curve to make it 3D. That simplifies the problem by a step already.
If the open area in the middle is big enough and you choose the right lerp method for the height, the decline in height near the open area probably won’t cause it to intersect other buildings.
But it’s a helicopter – the whole point is that they can land and take off vertically. Are you looking for a curve at a fixed height that avoids buildings, and then lowers over the drop zone? Or are you looking for a roundabout curve that loops around a bit and gradually lowers into the drop zone?
I don’t see the connection between what I said and this file though, I’m not even sure I understand how you’re making the heli move right now. It doesn’t look like a smooth curve at all to me
I’d write something up but I don’t really have time right now, maybe someone else can come up with the implementation I described above, if not I’ll try something later on
Gradually lowers towards the dropzone, if needed it can also drop vertically 15 studs above the landing zone but the path to that point should be smooth.
It’s not a curve, I give you that, but its a script that checks if the given path is obstructed, in which case it checks a spot higher up until the path is unobstructed.
So what I meant was to generate the smooth curve beforehand in such a way that you’re sure it won’t intersect any buildings, then you don’t need to do these checks and/or adjust the heli mid-flight. This works as long as the map is static, which I assume is the case?
Drawing a path in 2D, even if drawn on the top of the highest building, will not ensure that the heli won’t collide with anything. I dont see your point…
What do you mean exactly by curve? Do you want the helicopter to reach the point by making curves on the x/z axis (like a snake), or do you mean curve as in smoothly letting the helicopter go over buildings to reach the point above the end point, then lower down? Or both?
Is the map static, or is it dynamic?
And also note that helicopters tend to fly directly ontop of a point, then lower. They always fly way above the buildings, so I’m not sure why you would even need this. Just figure out the tallest point, then have the helicopter fly above it.
The issue here doesn’t seem to be pathfinding, but rather path following. You want the helicopter to follow a path, but feel dynamic and alive. I suggest you read The Nature of Code, Chapter 6, which discuesses autonomous agents.
I would solve this using path-finding and spline interpolation.
If you use a technique such as A* to calculate a 3 dimensional path using a grid, remove any nodes that aren’t important and then interpolate a spline through the points and you’ll get something like what you’re after.
As far as generating nodes for the helicopter to navigate, you’re gonna have a bad time. You’d be better off just manually placing nodes around, calculating which ones can see each other, then doing an A* navigation from the node the helicopter spawns at, to a landing node. With that, you can do a beziér curve interpolation through the A* path, do some angled tilting of the helicopter’s BodyGyro towards where the helicopter is trying to move, and you should get the motion fluidity that your looking for. I’ll see if I can make an example when I get the chance.
This might be a bit overkill, but for trying to fly between buildings you could generate a voronoi diagram with buildings as nodes. Then possibly combine it with A* (if you need obstacle avoidance) where being closer to a line on the diagram (i.e. midpoint between buildings) has a lower cost than flying close to a building.
I think “realism” is an optimization problem of energy required to get a helicopter from one point to another. This involves lots of math and probably doesn’t have a nice realtime generation function beyond a visually similar approximation. tbh RocketPropulsion with a moving target sounds like a reasonable solution.
I found a semi realistic version that I’m going to use now. It looks good and works most cases.
I’ll bump this later if I need a better version than this.