Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I go about creating a drone that avoids player line of sight?

Asked by
AZDev 590 Moderation Voter
4 years ago

Okay, so I don't have any code. I don't even really know where to begin at this point.

I guess some background information on implementation would be useful.

The player will be stationary behind cover only able to look around in all directions.

The drones will fly in from all directions and orbit the player remaining within 20 studs of the player while attacking. The idea is, when the player takes aim, the drone will move in a direction so as to avoid the players line of sight, thus avoiding fire from the player.

My first thought would be to have the drone cast a ray repeatedly at a reasonable rate and change it's direction if the ray hits the front of the player. This would be a rather simple implementation but I feel like it will look and feel clunky in game play.

My second thought, which based on my skill level and understanding of how the viewport works would be a rather difficult and involved implementation; would be to generate a line of sight using the players viewport and feed that information to the drones. I remember somebody created a module for converting between worldspace and screenspace. I believe it was crazyman32.

My third thought, would be to check if the player is looking in roughly the opposite direction of the drone. Which would involve comparing the unit lookVector of both the player and the drone. I feel like this could be clunky and inefficient as well. On top of that, aesthetically, the movement of the drone would feel scripted.

Not necessarily looking for code, though it would be useful. More or less looking for how you would implement this idea and maybe some insight into my ideas and what you think about them.

If you like my second idea and feel that's the best way to go, I may need some help in that aspect. I could learn but at this point, I don't know how I would cast a line of sight based on the aspect ratio of the players screen.

1
This isn't an answer, but good luck! This sounds amazing and really cool, kinda like skynet. Black_Sea 11 — 4y

1 answer

Log in to vote
1
Answered by
dreamy67 135
4 years ago

If the game were a third person shooter so I would most likely take the coordinates of the mouse, then I would use the WorldToScreenPoint function to check the location of the drone, in terms of the location on the user's screen. If the distance between the two points on the screen were less than a certain threshold, then I would assume the player is attempting to aim at the drone, and would calculate the direction to fly in to escape the players screen the fastest.

If the game were a first person shooter, I would do the same thing but instead of using the coordinates of the mouse I would just use the coordinates for the center of the screen.

0
Hm.. I'll see what I can do. I'm not familiar with the WorldToScreenPoint method. AZDev 590 — 4y
Ad

Answer this question