Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Movement AI question, suggestion needed - Gideros Forum

Movement AI question, suggestion needed

piepie Member
edited December 2018 in Game & application design
I am asking for help on a logical/math issue I've stumbled upon: this is part of the AI that should move the enemy horde in a tower defence game.
I know the locations of the waypoints were the enemies should go

waypoints = {{x,y}, {x2,y2}, {x3,y3}...}

and I've got 3 skill levels on each enemy type, meaning that enemy at skill level 1 uses enemy.speed[1], level 2 enemy.speed[2]...

enemy.speed = {0.5,0.7,1}

this is pseudocode for the enterframe function that moves them, and worked perfectly until I decided to use decimal numbers in my speed tables; but it won't work if I don't reach integer coordinates, equal to my waypoint coordinates.
function onEnterFrame()
	--This is the "check" I need to change: using decimal numbers getX() won't ever reach integer coordinates, unless I use only 0.2 and 0.5...
	if enemy:getX() == waypoint.x and enemy:getY() == waypoint.y then
		set next waypoint
	elseif enemy:getX()waypoint.x then
		enemy:setX() = enemy:getX() - enemy.speed[enemyskill]
	...the same applies with Y position...
The issue is that I'd like to use decimal numbers to differentiate speeds (there is already too much gap between 1 and 2 pixels per frame) but I need to find a better check to perform, to understand when they need to change waypoint.
Any suggestion for a math trick or a different approach?

Thank you


Sign In or Register to comment.