Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark Physics & Dark A.I. & Dark Dynamix / Dark AI in 2D...With sprites?

Author
Message
BULLSHOCK 2
Retired Moderator
19
Years of Service
User Offline
Joined: 14th Jun 2005
Location: Shocking Bulls
Posted: 15th Jan 2010 23:42 Edited at: 15th Jan 2010 23:47
Ok, i have looked everywhere for what i need but i cant seem to find it.

I know there is a 2d example in the DarkAI help file, but it didn't help (the example doesnt scroll the map).

Basically, I have a 2D top down shooter game that im working on, and the way Ive set up the camera system, it scrolls the entire tiled level left when you move right, it scrolls the level right when you move left...ETC, same with up and down, which simulates a camera.

Its simple enough, and it works, but my problem comes with dark AI. I want to use it in automatic mode, but I need to scroll the entities along with the map, and I cant seem to find a way to do this while keeping their original positions so they are always in the same position regardless of where the map has scrolled.

The way I have it set up, is 0,0 is the top left corner of the map, the MAPSIZExTILESIZEis the bottom right of the map, and I have mapScrollX, and mapScrollY variables...The way im getting static objects to move with the map is simply by subtracting the map scroll values from the objects position, but this wont work with dark ai, as it would confuse the entities, not to mention cause problems with interaction.

So two things, first, am I even setting this up correctly? and second, does anyone have any theories or ideas on how I would pull this off?

Thanks for all your help!

http://www.fpsc.seqoiagames.com
Airslide
20
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 19th Jan 2010 00:46 Edited at: 19th Jan 2010 00:56
Keep the drawing positions independent from the 'real' positions. If you store the 'real' position of each static, then just re-draw the sprite at that position + the scroll values. For the AI, draw their sprites at the AI's position + the scroll values. Don't actually move the statics/AI entities, just their sprites. Should work like a charm

EDIT: Some (untested) example code:



BULLSHOCK 2
Retired Moderator
19
Years of Service
User Offline
Joined: 14th Jun 2005
Location: Shocking Bulls
Posted: 19th Jan 2010 00:53
Ive already tried that, but the problem is that the interactions with the player become distorted the further the sprite's scroll from their original position. The AI doesn't react to the player, because it is still technically in the distance, not next to you like the sprite. Unless im missing something?

Thank you for your help though!

http://www.fpsc.seqoiagames.com
Airslide
20
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 19th Jan 2010 00:56 Edited at: 19th Jan 2010 01:08
Edited the example code (not sure if you saw it).

If you do what I did for the 'statics' array there it should work fine with AI and players. As long as the player's position has a 'real' value that is independent from the camera, you should be fine.

EDIT: Here, look at this. There was a little more to it than I originally thought - and you have to subtract the cam values, not add...



BULLSHOCK 2
Retired Moderator
19
Years of Service
User Offline
Joined: 14th Jun 2005
Location: Shocking Bulls
Posted: 20th Jan 2010 03:21
Airslide, THANK YOU!

I feel stupid. I have almost identical code to what you've posted, except without the player having a "Real World" coordinate.

I was so set on trying to bring darkAI into 2D that I forgot about the possibility of bringing my character into 3D.

Thank you, that works perfectly!

http://www.fpsc.seqoiagames.com
Airslide
20
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 20th Jan 2010 05:58 Edited at: 20th Jan 2010 05:59
No problem

Although I'm not sure we brought your character into 3D

All we're really doing is adjusting how things are drawn based on where the camera is, as opposed to where they are You could probably optimize a bit from there, not drawing things outside the camera view and such. If you're using sprites, I believe you can hide the sprite and then manually use paste sprite for a performance boost as well.

BULLSHOCK 2
Retired Moderator
19
Years of Service
User Offline
Joined: 14th Jun 2005
Location: Shocking Bulls
Posted: 20th Jan 2010 08:54
No haha I get that.

I didnt actually get anything from your code(thank you though!), just this little bit:
Quote: "As long as the player's position has a 'real' value that is independent from the camera, you should be fine."


That set off one of those AH HA! moments in my head and ive got it working in my game now.

Its still technically 2 dimensions, but my player only had a screen coordinate...so thats what I meant. just needed to get him a real coordinate and everything worked.

Im using the 2d plugin kit for layers in 2D as of now, but I think as you mentioned it may be much better for performance if I write my own system and not draw things outside of the screen(im not sure if the kit does that automatically or not), although the kit seems to handle everything pretty fast so far...


Thanks again!

http://www.fpsc.seqoiagames.com

Login to post a reply

Server time is: 2024-11-24 15:01:33
Your offset time is: 2024-11-24 15:01:33