Discuss Scratch

oscarcarterwoodleigh
Scratcher
4 posts

AI Character oscillating when idle.

I am making a dragon ball fighting game as a project. In the game, you control a character and fight against an AI-controlled opponent. I am currently making the AI opponent always match your y position, and always move towards a point to the right of the player. This works fine most of the time, but sometimes, if I move around quickly or erratically, the enemy character begins to oscillate back and forth really quickly. Here is a link to the project (the issue is in the “Trunks” sprite): https://scratch.mit.edu/projects/296201439/

My browser / operating system: MacOS Macintosh X 10.12.6, Chrome 72.0.3626.121, No Flash version detected

Last edited by oscarcarterwoodleigh (March 21, 2019 22:21:56)

deck26
Scratcher
1000+ posts

AI Character oscillating when idle.

Please share the project, not a screen shot.
Isajah
Scratcher
25 posts

AI Character oscillating when idle.

the first two larger if/else conditions are the exact same. is what I see on first glance. also x>player_x is always true, when x > player_x +125 is true.
thats redundant logic, if im not missing anything

x = player_x AND x < player_x + 125 also doesn't make much sense, logically speaking.

also equality is always bad, when talking about position and gliding numbers. just as a general recommendation, use a delta like

same_height := my_y < your_y + delta and my_y > your_y - delta // delta = 5

Last edited by Isajah (March 21, 2019 10:41:10)

oscarcarterwoodleigh
Scratcher
4 posts

AI Character oscillating when idle.

deck26 wrote:

Please share the project, not a screen shot.

I have added a link to the project.


Isajah wrote:

the first two larger if/else conditions are the exact same. is what I see on first glance. also x>player_x is always true, when x > player_x +125 is true.
thats redundant logic, if im not missing anything

x = player_x AND x < player_x + 125 also doesn't make much sense, logically speaking.

also equality is always bad, when talking about position and gliding numbers. just as a general recommendation, use a delta like

same_height := my_y < your_y + delta and my_y > your_y - delta // delta = 5

I'm sorry, I am not very knowledgable about technical things, and have no idea what a delta is. Thanks for answering, but maybe you could explain your answer, as I don't quite get it.
oscarcarterwoodleigh
Scratcher
4 posts

AI Character oscillating when idle.

Isajah wrote:

the first two larger if/else conditions are the exact same. is what I see on first glance. also x>player_x is always true, when x > player_x +125 is true.
thats redundant logic, if im not missing anything

x = player_x AND x < player_x + 125 also doesn't make much sense, logically speaking.

also equality is always bad, when talking about position and gliding numbers. just as a general recommendation, use a delta like

same_height := my_y < your_y + delta and my_y > your_y - delta // delta = 5


Actually, I have figured it out and fixed my code. Thanks for helping!

Powered by DjangoBB