Blender Can Do RTS

I kind of agree with BlueCarrot, the most cpu intensive task here will be both physics and logic, physics because of the barracks that will stop the characters or that the characters don’t trespass each other for example, and logic because of the AI of each character, if we talk about playing against the CPU and not another player. But also AI would be needed so the characters knows when and how to stop ar certain spot or start the counter attack in case of an enemy attack.

Anyways an RTS is an interesting problematic I would like to see how this progress. Also a tactics game would be interesting (and easier to make for multiplayer), but way a lot harder to make an AI for it in case of going against the cpu.

Interesting and true.
I am planning to work on the project in this order:

  • Create blocks that resemble infantry. (hehe… easy)
  • Basic production system. Probably a prototype for ONLY the barracks.
  • Basic AI.That’s on my list right now. Later on I will work on the graphics and sound.

Thanks. I agree with BlueCarrot too as you might have noticed and I will try to work around the problem if it occurs really soon. The physics won’t use up a lot of memory in the future since the physical world will consist of bounding boxes. The AI will cast rays to find out wether they are facing an object or not. The basic system would be that they would avoid those objects and check for ‘safe-move’ locations using a Radar sensor. I might start working on this today (it’s 09:00 here) . Coding takes time. So let’s do it!

Thanks for your replies,

- AniCator

PS: SOMEONE TRIED TO LOG IN ON MY ACCOUNT!
HERE’S HIS/HER PUNISHMENT: 212.143.129.203 !!!

The person that tried to log in lives in Israel according to a website I used to trace the IP’s location.

While I applaud your efforts, I too am concerned about the logic. Just for a reference, I have this script running on 48 coins in a game and the logic is already at 20%.


import pygame.mixer as m
m.init()

cont = GameLogic.getCurrentController()
own = cont.getOwner()

#Sensors

#None

#Actuators

message = cont.getActuator("message")
end = cont.getActuator("end")

#Process

player = GameLogic.getCurrentScene().getObjectList()["OBgel"]
distance = own.getDistanceTo(player)

if distance < 3.00:
    m.Sound("data/sounds/coin.ogg").play()
    GameLogic.addActiveActuator(message, 1)
    GameLogic.addActiveActuator(end, 1)

I would think that an rts would have much more complicated scripts running on more objects. But still, keep going. I love to see people doing this kind of stuff with Blender. :slight_smile:

I kind of disagree with bluesocarrot. (go Australia!)

Writing 300 line scripts for every unit is silly, id say 4 scripts for all the units, ground units water units air units and buildings.

and you just run an instance of the script.

I’m not too crash hot with python methods and classes, but heres a basic idea.

All the unit info is stored in this set and can be retrieved using data = Data.new, data.buildings(0) to retrieve the barracks.
The array for buildings is [ID, object name, object type (like 1 unit production or 2 attacking building), hp, units that can be built from it, attack range, attack.
The array for units is [ID, object name, hp, type 0 = ground 1 = water 2 = air, hp, attack range, attack.
So here, a barracks can build infantry and rocketers.


class Data:

def __inti__:
buildings_data = [[0, "barracks", 1, 200, [0, 1], 0, 0],[1, "watch tower", 2, 120, 0, 8, 12]]
units_data = [[0, "infantry", 0, 50, 5, 8],[1, "rocketer", 50, 5, 15]]
buildings = []
units = []

retrieve_data(type, id=0):
if (type == 0):
return buildings_data(id)
elif (type == 1):
return units_data(id)
elif (type == 2):
return buildings
elif (type == 3):
return units

def append(type, data):
if (type == 0):
buildings.append(data)
else:
units.append(data)

This is the class for buildings


class Building:

def __init__(id, object, owner, unit_status, hp):
Game_Logic.data.append(id, object, unit_staus, hp)
current_status = 0

def id:
return id

def object:
return object

def owner:
return owner

def unit_status:
return unit_status

def hp:
return hp

def current_status:
return current_staus

def idle?:
 if (current_status == 0):
 return True
 else:
 return False

def building?:
def attacking?:
if (current_status == 1):
return True
else:
return False

def attacking?:
if (current_status == 2):
return True
else:
return False

and for the actual building

id = len(Game_Logic.data.retrieve_data(0))
properties = Building.new(id ,"baracks", 2, 1, [200,200])

This way our 100 units with 300 line scripts each gets reduced 100 units with 10 line scripts and 6 300 line scripts.

Well, now that I got that out of the way, it looks good anicator. Are you planning on making a game out of the this?

The same happened to me today. I got an email telling me someone had used up the 5 tries and my account had locked itself for 15mins, lucky…

Nearly identical IP address, only different by the last number. I wonder who it is, and what their up to… Either way i dont really appreciate it.

Nice work btw AniCator, ill be watching this to see how it goes.

well as I see it there are several strategies that can be taken in order to reduce CPU load.

for one you can implement a group logic scheme, in other words, if a unit is included as part of a group (as in proximity and control) you can decimate its own logic and have it submit its will to the group mind. This could theoretically turn a 100 unit battle into a battle between a hand full of group minds.

Another is to have rally points around the map. Points that if they are under attack, they will call out to the group AI within a certain range. This way the unit AI will not have to include a check for aggression but instead they will simply listen out for a call of attack only when one occurs.

Then add a formula to have a delay for when the closest unit to the action is in order to calculate distance. This can give the impression that each unit is thinking on its own but really it’s just a certain delay + a certain random modifier + distance modifier all based upon 2 macro AI’s (1 AI point + 1 Group AI)

I’m sure there are a thousands way to do it though.

If you do pathing I’d suggest the Starcraft model. Just have one unit find the path, while the others fall in single file if it’s a long distance. If it’s a short distance with easy pathing then have them make their own way since it would be much simpler then.

And I think there is a thousand a one ways to have an RTS work in BGE.

The Ray-Tracing Cursor Height Controller

Yeah. I think it sounds nice.
The problem is that it works only partially. I get it to position the cursor on the terrain but after that it doesn’t respond any more.

To make myself clear:A new timelapse video: Link

And the code:

#Ray-Tracing Cursor Height Controller
#Coded by: AniCator

import GameLogic

con = GameLogic.getCurrentController()
own = con.getOwner()
sens = con.getSensor("RayTerrain")

hit = sens.getHitPosition()
pos = own.getPosition()
pos2 = [pos[0],pos[1],hit[2]]
own.setPosition(pos2)

Thanks for reading,watching and listening,

- AniCator

EDIT: It works a lot better now but it still is a bit buggy. The RaySensor must be missing something making it reset the Z to 0.00. I’m working on it.

#Ray-Tracing Cursor Height Controller
#Coded by: AniCator

import GameLogic

con = GameLogic.getCurrentController()
own = con.getOwner()
sens = con.getSensor("RayTerrain")

pos = own.getPosition()
hit = sens.getHitPosition()
hit2 =hit[2]+.1
pos2 = [pos[0],pos[1],hit2]
own.setPosition(pos2)

EDIT2: Display Lists have not been used, yet.

wow.
cool.
but better graphics, maybe.

Yep…maybe.
But it won’t be an RTS game without RTS code.
No problem. I’m not sure if I will work a lot on the graphics. I was thinking about doing that in another ShortGame project.

I personally would use this engine and make super high quality renders of your buildings and units and hud and such. If you get good enough renders, your game could look like Project Revolution Mod for Warcraft 3, which makes Warcraft EXACTLY like starcraft, except nicer graphics. Take a look and youll see what i mean.

Also, as far as terrain, Make it less…hillish, and make it so you cant build on slope. That way you dont have to worry about ugly half inground buildings and you can make more stradigy to it, Also the maps would be ALOT less polys. And saying how 7 fps is great because you got 200 barracks is dumb! That is only because you have barely any code compared to a final game along with other shaders you may add later.

Erm, whats RTS? I should know it, but forgot. And that looks like a lot more than 250 tents LOL!!!

I mean in the first post.

Real Time Strategy

About the mouse thing.
why not just use blendenzo’s script and then set the UV mode to shadow??

Starcraft, Starcraft 2, Warcraft 1,2,3, Command and Conqure series, some Starwars games, Lord of the Rings Battle for the Center of the Earth or something like that, a buch more too.

Basicly, you build your base and get units as fast and as statigicly as you can while the enemy does the same

Hehe… I forgot about that. I wonder if the GLSL builds are already supporting decals. That would be very nice for the cursor.

The terrain is made for testing. The center area is the actually area in which you are supposed to build in the current version.

Feel free to ask questions. I’ll post a .zip with the current files within a few days so you can play around with it. I’m currently working on the basic AI. It is supposed to target an enemy but it seems like they don’t feel like it yet. The Ray sensor doesn’t trace the enemy’s properties.

- AniCator

Interesting project. The AI will be a challenge.

I’ve heard that the ray sensor can be quite demanding of resources though. If there are limited amount of objects then might it be more efficient to iterate through them using getDistanceTo() ?


enemyUnits  = {unit1, unit2, unit3, unit4}
for unit in enemyUnits:
     if player.getDistanceTo(unit) < 5:
          player.isClose = 1

Not too knowledgeable about BGE python, but maybe worth looking at.

Edit: I kinda got the impression that the ray sensor would be more useful in an application such as walking down a tunnel in a fps. If your objects are small then using the distance from the object center might be better, but if your objects (eg. walls) are large or long, it might be better to use the ray sensor.

like age of empires? :smiley:

My first attempt at simply making the AI target a hostile AI has failed already.
What do you suggest apart from a Ray sensor? Near sensor are very intensive sensors as far as I tried. I placed a few and it lowered the frame rate with a large amount.

I’m not sure which sensor to use, yet.

Yes, Age of Empires is a real-time strategy game.

- AniCator

Mmmm…
You could try using “track to” and calculate the distance as Funky said o.o

Logic Brick Setup:
http://www.anicator.com/sg/army/BlenderRTS.gif

Code:

#Red AI Test Script
#Coded by: AniCator

#Preperation
import GameLogic

con = GameLogic.getCurrentController()
own = con.getOwner

#Get Near sensor
ray = con.getSensor("Ray")
act = con.getActuator("Blue")

obj = ray.getHitObject()
if obj==str():
    act.setObject(obj)

- AniCator

good , know what it is this glitch ? , the red square changes color when it gets in a specific area !!
also , you can project your square on the floor by using shadows [glitchy a little] method or this python method

Attachments