Character AI-Roaming in scrolling-Loopable room

Started by jamesreg, Wed 06/02/2019 17:04:11

Previous topic - Next topic

jamesreg

Ok,

I know there are several post on Roaming Characters in a room and there are several different ways it can be done.

Let me explain my overall goals for this so someone can help me figure out the best way of going about it and where to get started.

About the Room:

1) Main Game room size is 480x270
2) Scrolling Background size is 3000x3000
3) The room is already set up to use a target gui in the center of screen and hidden mouse also always in center.
4) The room Scrolls and loops around the edges to the opposite side of the screen as it scrolls.

Needed Goals:

1) Need to be able to have characters which will be enemy ships traveling around on the screen at random Sometimes there will be more then one.

2) Need to have enemy ship characters be able to loop around the screen just like it does when scrolling and appear on the opposite side of the screen.

Right now this is my goals to get done but in case it is needed to know future plans in order to decide the best way to go with this ill also later be wanting to do the following.

1) When the view port comes in range of the character have it use its view to turn direction toward the screen and attack and fly back off
2) Have when it is damaged beyond a certain point to flee off again or at times cloak itself
3) Have some intelligent movement going on or be able to call up special moves or turns from different angles.
4) At Random cloak and uncloak later and attack (can ags gradually reduce/increase transparency or should I look into the tween mod for this?

This second part is more complex stuff right now I am seeking to figure out mainly the roaming around and loopable stuff but I know sometimes if we do not explain all we want to do then we find out something else we plan will not work with the way we went with code to get something else to work so I wanted to explain all I was hoping to achieve with this.

So what is the best way to look into doing this.

Right now I am trying this and it allows the Ship to move around randomly when it comes to a room border it turns around and heads another direction this will work if I have to do it this way as it does look fine but would be better if I get it to wrap the scrolling screen.

Code: ags
if (cRomulanShip.Room == player.Room) {
   if (cRomulanShip.Moving == false) {
     cRomulanShip.Walk(Random(Room.Width), Random(Room.Height));


So I am halfway there on my first couple things

Snarky

First the easy question to answer:

Quote from: jamesreg on Wed 06/02/2019 17:04:11
(can ags gradually reduce/increase transparency or should I look into the tween mod for this?

Yes and yes. AGS can do it, and you should probably use the tween mod to make it as easy as possible.

As the lack of responses perhaps indicates, the rest is potentially not an easy task, depending on exactly what you expect.

I take it what you're trying to achieve is some kind of space combat sim, sort of like Wing Commander, only from the viewpoint of the gunport of a "stationary" ship (so that you can't actually fly around dogfighting)?

The approach you've chosen has a few limitations:

  • "Have some intelligent movement going on" â€" What do you mean by this? What sort of movement and behavior do you want from them?
  • As you've currently coded it, they fly in a straight line from Point A to Point B, then immediately "bounce" and head in some other straight line to Point C. Is that the sort of movement you want, or do you want to try to get something that seems more physically realistic?
  • You don't have any notion of "distance" to the ships, they're all moving along a flat invisible surface in space (or, I guess technically around the surface of an invisible sphere with you in the center, assuming that's what the wraparound effect is mean to simulate). Is that OK, or do you want ships to come closer and move further away from you?
And another observation that raises further questions: Since your visible screen is only a small part of the whole room, ships will often be outside of the visible region. Should they still behave the same way when out of view? Should they be able to attack even when you can't see them, for example? Should new ships only spawn in the visible part of the room, or anywhere? Do you need some kind of indicator letting you know where they are?

The conventional way building something like this would probably be to do it in 3D, which would allow for fully "realistic" movement in space. But if you're not too comfortable with coding or with the trigonometry it takes to do the 3D calculations, you'll have to see how well you can fake it in 2D. You have some decisions to make:

Decision 1: Use Walk or move the ships around yourself
Walk is easier (you already have it), but very limited: the ships are only going to move at a fixed speed in a fixed line from Point A to Point B, and you won't be able to get them to wrap around in any reasonable way. (If you've done the wraparound the way I told you to, they'll also suddenly disappear or appear as your scrolling wraps around the edge.)

The other approach is to move them by changing their X and Y coordinates yourself. This gives you complete freedom to create curved paths and varying speeds, and you can implement the correct wraparound behavior relatively simply. But like I said, more complicated overall. To get somewhat realistic ship movement, you could store a movement and acceleration vector (which is simply a pair of X and Y values) for each ship, and each game loop you would:

1. Adjust the acceleration vector according to some rules (representing what the ship currently "wants to do")
2. Change the movement vector by the acceleration vector
3. Change the position by the movement vector
4. Wrap around

Decision 2: Implement any kind of "AI"
Enemy intelligence in games is usually pretty simple. The most common way is to give each enemy a few different "states" to switch between. In each state they follow some particular simple rule of what to do, and then they switch to another state when some condition is fulfilled. For example, ships could have states like "circling", "dodging", "distracting", "attacking" and "fleeing". Here, "circling" would be some variation of the "random movement" you already have implemented. "Dodging" would tell it to change direction more often, maybe speed up. "Distracting" would head towards the region of your viewport, close to but not directly under the targeting aim. "Attacking" would carry out an attack (if you have several, just pick one at random), and "Fleeing" would, well, flee (maybe engaging cloaking if available).

Then you have a rule that says, for example: If you're in the "circling" state and the player shoots somewhere closer than 10 pixels from you, switch to the "dodging" state. And another rule that says: If you've been in the circling state for more than 40 seconds, switch to the "attack" state. And another that says: If the player attacks another ship and its health/shield level is less than 33%, and you're less than 300 pixels away, go to the "distract" state. And so on. You add rules for transitioning from each state to each of the other states that make sense. (Usually you have at least a transition back to the "default" state, "circling", from every other state.)

The collection of states and rules for transitioning between them is called a state machine, and is very common for this kind of task. You can achieve surprisingly complex, "intelligent" behaviors with just a few states, some very basic behaviors in each state, and smart rules for transitioning between them.

jamesreg

QuoteI take it what you're trying to achieve is some kind of space combat sim, sort of like Wing Commander, only from the viewpoint of the gunport of a "stationary" ship (so that you can't actually fly around dogfighting)?

Yes Pretty much like Wing Commander and very much like Star Trek 25th Anniversary and Judgment rites set up where you see stuff though the view screen. you never see your ship just the enemy ships in the screen.

Quote"Have some intelligent movement going on" â€" What do you mean by this? What sort of movement and behavior do you want from them?
As you've currently coded it, they fly in a straight line from Point A to Point B, then immediately "bounce" and head in some other straight line to Point C. Is that the sort of movement you want, or do you want to try to get something that seems more physically realistic?
You don't have any notion of "distance" to the ships, they're all moving along a flat invisible surface in space (or, I guess technically around the surface of an invisible sphere with you in the center, assuming that's what the wraparound effect is mean to simulate). Is that OK, or do you want ships to come closer and move further away from you?

1) More Physical Realistic
2) A distance system where they will appear closer and further away at times.
3) The wrap around was meant to keep you from hitting the edges and stopping. But I do not like how the characters disapear when you are close to one. id like for them to be able to wrap to or confine them far enough away from the borders you never notice anything odd with them appearing disappearing strangely.

QuoteAnd another observation that raises further questions: Since your visible screen is only a small part of the whole room, ships will often be outside of the visible region. Should they still behave the same way when out of view? Should they be able to attack even when you can't see them, for example? Should new ships only spawn in the visible part of the room, or anywhere? Do you need some kind of indicator letting you know where they are?

Yes I am working right now on a radar system that will show My location and enemy ships locations as a little dot on a grid. I used hot spots to separate areas of the background off then move the dot to the location on the radar grid if they were in that hot spot area. However I thought I could do the same thing with my location using if mouse is over hot spot beings my mouse is always center screen figured it would work but it does not for some reason.

As far as rather they can attact or react if still in my viewport but off the part thats out of the viewscreen in the middle that is fine as your know you close to them because of radar and its not an issue.

QuoteNo nowhere near comfortable enough coding it that way or good enough at math to do it that way. Besides faking it out even though less perfect will go with the retro look of the rest of the game like other games from that era did.

QuoteDecision 2: Implement any kind of "AI"
Enemy intelligence in games is usually pretty simple. The most common way is to give each enemy a few different "states" to switch between. In each state they follow some particular simple rule of what to do, and then they switch to another state when some condition is fulfilled. For example, ships could have states like "circling", "dodging", "distracting", "attacking" and "fleeing". Here, "circling" would be some variation of the "random movement" you already have implemented. "Dodging" would tell it to change direction more often, maybe speed up. "Distracting" would head towards the region of your viewport, close to but not directly under the targeting aim. "Attacking" would carry out an attack (if you have several, just pick one at random), and "Fleeing" would, well, flee (maybe engaging cloaking if available).

Then you have a rule that says, for example: If you're in the "circling" state and the player shoots somewhere closer than 10 pixels from you, switch to the "dodging" state. And another rule that says: If you've been in the circling state for more than 40 seconds, switch to the "attack" state. And another that says: If the player attacks another ship and its health/shield level is less than 33%, and you're less than 300 pixels away, go to the "distract" state. And so on. You add rules for transitioning from each state to each of the other states that make sense. (Usually you have at least a transition back to the "default" state, "circling", from every other state.)

The collection of states and rules for transitioning between them is called a state machine, and is very common for this kind of task. You can achieve surprisingly complex, "intelligent" behaviors with just a few states, some very basic behaviors in each state, and smart rules for transitioning between them.

This sounds more like or exactly like the things I wanted it to be able to do. I wanted an AI thing like that and then the ability to script or call up certain things on command if I wanted to as well.

My hopes it to use that one battle room we created earlier this week and use it for multiple battles and script it to know which battle im in and which ships etc to put there and what their moves are and such.

I'll let you review my answers and then you can advice further on what I need to do or be looking into to achieve this stuff.



SMF spam blocked by CleanTalk