Discuss Scratch

MTM828
Scratcher
500+ posts

A.I. enemies in a scrolling platformer

I made a scrolling platformer, went really well, blah, blah, blah, but there was a problem with the enemy in my project the enmy;
  • Sinks through the ground
  • Switches to hitbox costume for a long time
  • Causes sudden lag
  • Acts weird
Even though I used the same physics engine as the player but with different variables exclusive to the enemy. I hope you can find the bugs and fix them, thanks!

Last edited by MTM828 (Aug. 18, 2020 19:46:51)

MTM828
Scratcher
500+ posts

A.I. enemies in a scrolling platformer

Never mind I fixed all the bugs but 1: When the enemy reaches the edge it effects him quite a lot, for example, if there's a wall between you and him and you move, he hits the wall and thus goes inside, goes crazy, switches to hitbox blah, blah, blah. I hope if you can help me with this, and why isn't anyone replyig?

Last edited by MTM828 (Aug. 24, 2020 14:58:25)

MTM828
Scratcher
500+ posts

A.I. enemies in a scrolling platformer

Hello?
Karshd
Scratcher
5 posts

A.I. enemies in a scrolling platformer

MTM828 wrote:

Never mind I fixed all the bugs but 1: When the enemy reaches the edge it effects him quite a lot, for example, if there's a wall between you and him and you move, he hits the wall and thus goes inside, goes crazy, switches to hitbox blah, blah, blah. I hope if you can help me with this, and why isn't anyone replyig? plus I asked help from someone on another topic but a very kind person who I don't want to embarrass told me to create a new topic, so I did, but he didn't even LOOk at the new topic. Well, anyway forget everything after:
and why isn't anyone replyig?
Hmmm mabe make him go out of the wall by making code which telepotts him if he goes into a wall. Put a large sprite, set the ghost effect to 100 on the sprite and make it so that it is invisible. then make him teleport .
MTM828
Scratcher
500+ posts

A.I. enemies in a scrolling platformer

Karshd wrote:

MTM828 wrote:

Never mind I fixed all the bugs but 1: When the enemy reaches the edge it effects him quite a lot, for example, if there's a wall between you and him and you move, he hits the wall and thus goes inside, goes crazy, switches to hitbox blah, blah, blah. I hope if you can help me with this, and why isn't anyone replyig? plus I asked help from someone on another topic but a very kind person who I don't want to embarrass told me to create a new topic, so I did, but he didn't even LOOk at the new topic. Well, anyway forget everything after:
and why isn't anyone replyig?
Hmmm mabe make him go out of the wall by making code which telepotts him if he goes into a wall. Put a large sprite, set the ghost effect to 100 on the sprite and make it so that it is invisible. then make him teleport .
hmmm… yeah or:
when green flag clicked
forever
if <touching [edge v] ?> then
hide
end
end
or anything like that. But I'd really appreciate a way to make him exit the stage.

Last edited by MTM828 (Aug. 22, 2020 17:59:17)

minecraft_sprite
Scratcher
36 posts

A.I. enemies in a scrolling platformer

I assume that your enemies are just moving side to side. If this is the case, then you can use glide blocks for each. For example:
glide (1) secs to x: (0) y: (0)
glide (1) secs to x: (100) y: (0)
However, if you want gravity to affect them, that is a different matter entirely. You could try setting a random direction, and set barrier walls to the farthest point the enemies can move.
Tell me if you want an example.
MTM828
Scratcher
500+ posts

A.I. enemies in a scrolling platformer

minecraft_sprite wrote:

I assume that your enemies are just moving side to side. If this is the case, then you can use glide blocks for each. For example:
glide (1) secs to x: (0) y: (0)
glide (1) secs to x: (100) y: (0)
However, if you want gravity to affect them, that is a different matter entirely. You could try setting a random direction, and set barrier walls to the farthest point the enemies can move.
Tell me if you want an example.
No, no, no, no, no. I think you didn't get the point, I've created a scrolling platformer, and I added an enemy sprite (no clones used). I've pretty much perfected it! But there's just 1 problem, look at this example (P means player, W means wall or platform and E means enemy):
WWWWWWWWWWWWW


W
W
P W E
WWWWWWWWWWWWW
The enemy (marked in E) should run to the wall and try to catch the player right? Yeah no problem occurred! But what if the player (marked with P) moves to the left? It should look like:
WWWWWWWWWWWWWW


W
W
P W E
WWWWWWWWWWWWWW
What if the player moves ANY further? That would SQUEEZE the enemy into the edge! OK right? WRONG! Why is that? Because of Scratch preventing sprites from exiting the stage . That's the only problem left.

Last edited by MTM828 (Aug. 22, 2020 21:13:39)

deck26
Scratcher
1000+ posts

A.I. enemies in a scrolling platformer

If the only problem is a sprite not going off screen see this demo https://scratch.mit.edu/projects/419039062/
Oumuamua
Scratcher
1000+ posts

A.I. enemies in a scrolling platformer

You do that what @deck26 did, or create, in costume editor, a bigger invisible frame surrounding your main costume

https://scratch.mit.edu/projects/400445317/

Last edited by Oumuamua (Aug. 24, 2020 15:39:43)

MTM828
Scratcher
500+ posts

A.I. enemies in a scrolling platformer

deck26 wrote:

If the only problem is a sprite not going off screen see this demo https://scratch.mit.edu/projects/419039062/

Oumuamua wrote:

You do that what @deck26 did, or create, in costume editor, a bigger invisible frame surrounding your main costume

https://scratch.mit.edu/projects/400445317/
1st of all: thanks for the tutorials guys but I know how to do that, I even made a tutorial about it myself! 2nd: all I'm having trouble with is applying it to the platformer. Third is: why are people advertising? I know your helping but you can explain it yourself. Fourth: how do I make an invisible frame? And fifth: I'd appreciate it if you remixed the project with fixes. Thanks!
Karshd
Scratcher
5 posts

A.I. enemies in a scrolling platformer

MTM828 wrote:

Karshd wrote:

MTM828 wrote:

Never mind I fixed all the bugs but 1: When the enemy reaches the edge it effects him quite a lot, for example, if there's a wall between you and him and you move, he hits the wall and thus goes inside, goes crazy, switches to hitbox blah, blah, blah. I hope if you can help me with this, and why isn't anyone replyig? plus I asked help from someone on another topic but a very kind person who I don't want to embarrass told me to create a new topic, so I did, but he didn't even LOOk at the new topic. Well, anyway forget everything after:
and why isn't anyone replyig?
Hmmm mabe make him go out of the wall by making code which telepotts him if he goes into a wall. Put a large sprite, set the ghost effect to 100 on the sprite and make it so that it is invisible. then make him teleport .
hmmm… yeah or:
when green flag clicked
forever
if <touching [edge v] ?> then
hide
end
end
or anything like that. But I'd really appreciate a way to make him exit the stage.
Oh… sorry I can't help then
MTM828
Scratcher
500+ posts

A.I. enemies in a scrolling platformer

Karshd wrote:

MTM828 wrote:

Karshd wrote:

MTM828 wrote:

Never mind I fixed all the bugs but 1: When the enemy reaches the edge it effects him quite a lot, for example, if there's a wall between you and him and you move, he hits the wall and thus goes inside, goes crazy, switches to hitbox blah, blah, blah. I hope if you can help me with this, and why isn't anyone replyig? plus I asked help from someone on another topic but a very kind person who I don't want to embarrass told me to create a new topic, so I did, but he didn't even LOOk at the new topic. Well, anyway forget everything after:
and why isn't anyone replyig?
Hmmm mabe make him go out of the wall by making code which telepotts him if he goes into a wall. Put a large sprite, set the ghost effect to 100 on the sprite and make it so that it is invisible. then make him teleport .
hmmm… yeah or:
when green flag clicked
forever
if <touching [edge v] ?> then
hide
end
end
or anything like that. But I'd really appreciate a way to make him exit the stage.
Oh… sorry I can't help then
Hmm… Ok

Last edited by MTM828 (Aug. 25, 2020 15:18:35)

deck26
Scratcher
1000+ posts

A.I. enemies in a scrolling platformer

I always think of objects in a scrolling game as having ‘real world’ coordinates. These are fixed for non-moving objects but change for moving objects - which move in ‘real world’ terms. Scrollx/y are just adjustments which allow us to see where the objects are on screen (our window onto the real world).

So you should know the position of your sprites in screen coordinates, even if these are well off screen. If they are obviously off-screen you can just hide them. If they are obviously on screen (costume centre withing screen coords for example) you can show them. Otherwise you may need to hide them so it makes sense to then apply whatever method you want to use to get them to go as much off screen as you need.

If you still can't implement that you need to share your project of a simplified version of it.
MTM828
Scratcher
500+ posts

A.I. enemies in a scrolling platformer

deck26 wrote:

I always think of objects in a scrolling game as having ‘real world’ coordinates. These are fixed for non-moving objects but change for moving objects - which move in ‘real world’ terms. Scrollx/y are just adjustments which allow us to see where the objects are on screen (our window onto the real world).

So you should know the position of your sprites in screen coordinates, even if these are well off screen. If they are obviously off-screen you can just hide them. If they are obviously on screen (costume centre withing screen coords for example) you can show them. Otherwise you may need to hide them so it makes sense to then apply whatever method you want to use to get them to go as much off screen as you need.

If you still can't implement that you need to share your project of a simplified version of it.
Well, I don't know how I can simplify it more than this, I used Griffpatch's platformer tutorial and added scrolling (see the World sprite and the difference between the player and player in his tutorial). And if I used your tutorial that'll be recreateating the entire project, and I don't want to waste all the work and time put into it. I hope other people have ideas…
MTM828
Scratcher
500+ posts

A.I. enemies in a scrolling platformer

deck26 wrote:

I always think of objects in a scrolling game as having ‘real world’ coordinates. These are fixed for non-moving objects but change for moving objects - which move in ‘real world’ terms. Scrollx/y are just adjustments which allow us to see where the objects are on screen (our window onto the real world).

So you should know the position of your sprites in screen coordinates, even if these are well off screen. If they are obviously off-screen you can just hide them. If they are obviously on screen (costume centre withing screen coords for example) you can show them. Otherwise you may need to hide them so it makes sense to then apply whatever method you want to use to get them to go as much off screen as you need.

If you still can't implement that you need to share your project of a simplified version of it.
But what if I used my own collision detection? I remember I worked it out in Python (using Pygame), perhaps applying the off-screen script would work then because if I change size that would affect the hitbox, so if I create my own… then size won't affect it! Good thing I'm learning Python! But this might not work, any ideas?
deck26
Scratcher
1000+ posts

A.I. enemies in a scrolling platformer

I don't see where you've identified and shared the project which makes it harder to help. You say you added scrolling so how does that scrolling work? If it uses the normal scrollx/y method then what i suggested is not a problem - you'd still have a real world position which gives a screen position and you need to tell the sprite to move to that position. I don't know what you're doing that means my suggestin wouldn't work or that you'd need to create an entire new project. But since I'm in the dark about what you are doing I can't be sure about anything.
MTM828
Scratcher
500+ posts

A.I. enemies in a scrolling platformer

deck26 wrote:

I don't see where you've identified and shared the project which makes it harder to help. You say you added scrolling so how does that scrolling work? If it uses the normal scrollx/y method then what i suggested is not a problem - you'd still have a real world position which gives a screen position and you need to tell the sprite to move to that position. I don't know what you're doing that means my suggestin wouldn't work or that you'd need to create an entire new project. But since I'm in the dark about what you are doing I can't be sure about anything.
Oh sorry, I might of not been so clear. It works like a normal platformer but the only thing different is:
  • The (scrolling) platforms change X and Y by the player's positions (* -1) (with exiting the stage script).
  • After that they broadcast a message.
  • When the player (sprite) receives the message he resets his location.
So when the player moves, the ground moves in the opposite direction and tells the player to move back to Y: 0 X:0.

MTM828 wrote:

I made a scrolling platformer, went really well, blah, blah, blah, but there was a problem with the enemy in my project the enmy;
  • Sinks through the ground
  • Switches to hitbox costume for a long time
  • Causes sudden lag
  • Acts weird
Even though I used the same physics engine as the player but with different variables exclusive to the enemy. I hope you can find the bugs and fix them, thanks!
The link was mentioned here. But I admit my way of scrolling is unique and thus makes it hard to understand and help, but I appreciate your help greatly and you'll be credited. I thought I'd just make it stop scrolling if there's an enemy. But great that you came to help! I can't really explain the platformer physics in one message and I don't really have the time, I'll just tell you I got it from griffpatch_tutor's tutorial.
killrcreepr
Scratcher
8 posts

A.I. enemies in a scrolling platformer

MTM828 wrote:

Karshd wrote:

MTM828 wrote:

Never mind I fixed all the bugs but 1: When the enemy reaches the edge it effects him quite a lot, for example, if there's a wall between you and him and you move, he hits the wall and thus goes inside, goes crazy, switches to hitbox blah, blah, blah. I hope if you can help me with this, and why isn't anyone replyig? plus I asked help from someone on another topic but a very kind person who I don't want to embarrass told me to create a new topic, so I did, but he didn't even LOOk at the new topic. Well, anyway forget everything after:
and why isn't anyone replyig?
Hmmm mabe make him go out of the wall by making code which telepotts him if he goes into a wall. Put a large sprite, set the ghost effect to 100 on the sprite and make it so that it is invisible. then make him teleport .
hmmm… yeah or:
when green flag clicked
forever
if <touching [edge v] ?> then
hide
end
end
or anything like that. But I'd really appreciate a way to make him exit the stage.

If the enemy clone hides when touching edge how does it measure the distance away from the player because when the enemy is touching the edge it isn't moving any more further away from the player.
MTM828
Scratcher
500+ posts

A.I. enemies in a scrolling platformer

killrcreepr wrote:

MTM828 wrote:

Karshd wrote:

MTM828 wrote:

Never mind I fixed all the bugs but 1: When the enemy reaches the edge it effects him quite a lot, for example, if there's a wall between you and him and you move, he hits the wall and thus goes inside, goes crazy, switches to hitbox blah, blah, blah. I hope if you can help me with this, and why isn't anyone replyig? plus I asked help from someone on another topic but a very kind person who I don't want to embarrass told me to create a new topic, so I did, but he didn't even LOOk at the new topic. Well, anyway forget everything after:
and why isn't anyone replyig?
Hmmm mabe make him go out of the wall by making code which telepotts him if he goes into a wall. Put a large sprite, set the ghost effect to 100 on the sprite and make it so that it is invisible. then make him teleport .
hmmm… yeah or:
when green flag clicked
forever
if <touching [edge v] ?> then
hide
end
end
or anything like that. But I'd really appreciate a way to make him exit the stage.

If the enemy clone hides when touching edge how does it measure the distance away from the player because when the enemy is touching the edge it isn't moving any more further away from the player.
Yeah I know, it doesn't work, just help me fix the problem.

Powered by DjangoBB