I need help with AI.
<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?
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.
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;}
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.
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.
Try explaining in words what you want to happen, then you will get a much better answer.
Just put the executable in a zip file then it will upload fine.
Here's what your code does right now:
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.
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
Popular Topics
Advertisement