AI for Circular Motion

Need help with using DizzyAGE then look here
Grandad
Hard Boiled Egg
Posts: 1276
Joined: Sat Aug 08, 2009 10:47 am
Location: Balham - gateway to the south

Postby Grandad » Sun Jul 26, 2015 2:55 pm

Andy, having watched the video of Fantastic Dizzy, making a fish do a figure of eight is very simple just using AI as long as you remember a few basic rules.

The Moving Object has to have a status of 1 for the room update to work.

Set the Object tile with a target of the next ID number up (if the object tile is ID 200, set it's target to 201).

Use the Object tile as the targets, making them dynamic and mat - so the first one, would be 201 with a target of 202. It does make it easier to see exactly where the object tile is moving to on the map.

#def 32 is the speed at which the object tile is moving towards the next target tile. Generally, setting #32 to 4 is usually fine if the 'delay' of the object tile is 3. But you can make them different speeds, so if you set the first target tile (201) to def32 = 4 and then set the following one (202) to def32 = 6, the moving tile will speed up when it's moving towards target tile 202.

#def 33 is the direction the moving object tile is facing as it travels towards the next target tile. If the original tile is facing left, then as long as you want the object tile move left, leave def33 as 0. When you need it to flip set def33 as 1 for the target tile it's moving to.

Remember that when the next target file is at a higher or lower 'y' setting than the previous target tile, the engine will make the object tile move diagonally up or down till it reaches the 'y' setting and then continue in a straight line.

Finally make sure the last target tile has a target of the first target tile (I used 8 target tiles to make a figure of eight, so set target tile 208 to have a target of 201). For the center point of the figure of eight you can place target tiles on top of each other.

Obviously the room update is just setting the moving object tile as idx and using 'AIUpdateTrain(idx);' as the next line. As long as all the action is taking place in one room you don't need to add 'ObjPresent(idx);'.

Hope this doesn't sound like I'm treating you like an idiot. Best of luck! :v2_dizzy_thumbsup:

AndyG
Hard Boiled Egg
Posts: 208
Joined: Thu May 22, 2014 1:54 pm
Location: UK
Contact:

Postby AndyG » Sun Jul 26, 2015 3:37 pm

Thanks for that :) You can treat me like an idiot all you like, you'll usually be right. I knew about using waypoints like that (mostly through hours of trial and error) but I don't know why the thought didn't occur to me to use them like this. Actually, what I was mostly after was a way to control the speed like that, so it gradually slows down until it's going backwards, and so on in a loop. I was trying something like this:

Code: Select all

func UpdateRoom_1_1()
{
idx = ObjFind(80);
speedinc = 10;

ObjSet(idx,O_Y,ObjGet(idx,O_Y) + speedinc);
speedinc -=1;

ObjPresent(idx);
}


This doesn't work because the speedinc variable is reset every update, which of course makes sense. So it's a work in progress. I know you can adjust the speed with waypoints, but that would mean setting 10+ waypoints (and if I can set this as a function, I can call on it whenever and save lots of time!) Maybe I'm trying to be too clever...

AndyG
Hard Boiled Egg
Posts: 208
Joined: Thu May 22, 2014 1:54 pm
Location: UK
Contact:

Postby AndyG » Sun Jul 26, 2015 3:39 pm

Wait... I can assign the variable in the object properties in the map! I am indeed very stupid :v2_dizzy_biggrin:

Grandad
Hard Boiled Egg
Posts: 1276
Joined: Sat Aug 08, 2009 10:47 am
Location: Balham - gateway to the south

Postby Grandad » Mon Jul 27, 2015 10:10 am

it is possible to use a function without using AI but it can get longwinded as you would have to define each movement.

Code: Select all

func fish(id, aa, ab)
{
idx = ObjFind(id);
x = ObjGet(idx, O_ X) ;
y = ObjGet(idx, O_Y);
if (ObjGet(idx, O_STATUS) == 0)
{
x-=4;
y-=1;
ObjSet(idx, O_X, x);
ObjSet(idx, O_Y, y);
if (x<= aa) ObjSet(idx, O_STATUS, 1);
}
if (ObjGet(idx, O_STATUS) == 1)
{
x-=3;
y-=1;
ObjSet(idx, O_X, x);
ObjSet(idx, O_Y, y);
if (x<=ab) ObjSet(idx, O_STATUS, 2);
}


etc, and setting the status back to 0 to move back to the start. NB - just in case this post gets the same problem as Simon, the code after setting the object to 'y' is if the x axis is greater or less then aa, ab etc.

Then you could use the bits in brackets to define the object being used and aa and ab etc as the start points to change status.

Code: Select all

func UpdateRoom_1_1()
{
fish(100, 4200, 4100)
}


Of course, you would have to make each fish separate, but as the define is generic, you'd just have to change the the title to fish1, fish2 etc and set the coordinates in the room update.

Told you it was longwinded :v2_dizzy_eek:


cron