I need help with AI.

Started by
20 comments, last by Skeleton_V@T 18 years, 4 months ago
<source> if(adone.x <= 200) { adone.y = adone.y - 1; } if(adone.y <= 100) { adone.y = adone.y + 1; adone.x = adone.x + 3; } </source> When the image goes up and over right it stops and starts to shake at 200. Can someone tell me how to bypass this?
Advertisement
adone.x = adone.x + 3;
Imagine adone.x = 197 then adone.x = 200 then adone.x = 203, at this point, this statement will always yield false:
adone.x <= 200
To prevent that, the simplest solution is to set adone.x = 200 whenever (adone.x <= 200) is false.

Hth

Edit: I feel like this is not quite helpful, do you want the image to bounce around the screen ?. I'm not sure about your code correctness.
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
if(adone.x <= 200){    adone.y = adone.y - 1;//problem    //you are checking the X coordinate, but modify the Y coordinate    //either use if(adone.y<=200)    //or use adone.x -= 1;}if(adone.y <= 100){    adone.y = adone.y + 1;    adone.x = adone.x + 3;}

I'm making space shooter so I don't want it to bounce
It won't bounce if the condition around the 200 point on OY only allows it to increase on OX coordinate. I don't really know what you are trying to do, because if you are trying to move an object in XOY then you need to deal with both axes in the same compound "if" statement.
Can anyone recommend a free file hosting service? I think it would be helpful if you played.
http://www.savefile.com
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
That particular one doesn't alow executable files.Anyone aware of one that does?
I don't know exactly what you want to do, but perhaps you could try using AND/OR statements, or even just an ELSE statement, for the second 'if'.

Try explaining in words what you want to happen, then you will get a much better answer.
-Chris
Just put the executable in a zip file then it will upload fine.

Here's what your code does right now:
--------------------|        |         ||   2    |    1    ||        |         ||        |         ||--------|---------||        |         ||   3    |    4    ||        |         ||________|_________|


Quadrant 1: x = 201+, y = 0-100
adone will move down 1 and right 3 until y enters quadrant 4 (y = 101)

Quadrant 2: x = 0-200, y = 0-100
adone will move up one, then down one (cancelling to 0) and x will move right 3 until it enters quadrant 1

Quadrant 3: x = 0-200, y = 101+
adone will move up 1 until it enters quadrant 2

Quadrant 4: x = 201+, y = 101+
adone will not move

So maybe you could say what you're trying to do?
ie. "I want adone to move in a square, from 100,100 to 200,200"
or, "I want adone to move right and zig-zag up and down"
something like that... because your executable will most likely just show us how it doesn't work in a different way than your code has, when we really need to know what effect you want.

As for your first explanation, the code you pasted wouldn't stop moving right and then shake at x=200, so perhaps you should paste more of your movement code, or else make sure there are no typo's in the code you already pasted.

This topic is closed to new replies.

Advertisement