Jump to content
  • Advertisement
Sign in to follow this  
MPG

I need help with AI.

This topic is 4562 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

<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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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;
}


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Can anyone recommend a free file hosting service? I think it would be helpful if you played.

Share this post


Link to post
Share on other sites
That particular one doesn't alow executable files.Anyone aware of one that does?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!