Discuss Scratch

2021bracal
Scratcher
11 posts

Enemy clone move script.

Hello. I am creating a game where you protect your resources from enemies who will try to take them. The enemies have a script that makes them go to the resource storage. Because I want them to wobble left and right when they walk, I cannot have them point at the storage and move a few steps in that direction, as that would mean they can't turn left or right. So, I have it set up that they glide 5 seconds to storage. This works fine, until I introduce shooting. I can't seem to find a way to create a script that has it so when they are hit with a bullet, they pause their moving script and get knocked back, then continue moving.

Thanks for any help you can give.

Game Link

Last edited by 2021bracal (Jan. 2, 2024 23:40:45)

pika_boo
Scratcher
100+ posts

Enemy clone move script.

Good question!

I think what you need is what you stated before- point at the storage and move a few steps towards it, because once the glide is started it keeps going and can't stop.
How we would implement the wobble from left to right: If you want the wobble to be perpendicular to its movement direction you could make the sprite turn 90 degrees left/right, move a few steps then return to its original direction. You could smoothen this by adding a “wobble velocity”. After each wobble the variable changes, back and forth between two numbers, then move steps. If it is hit with a bullet you could just pause this cycle and make it move negative steps instead.

Hope that helps!
deck26
Scratcher
1000+ posts

Enemy clone move script.

Not that difficult. Point towards the end point and store that direction. Always point in that direction before moving the sprite n steps and then point in ‘wobble-direction’. In another script set ‘wobble-direction’ alternately to the stored direction plus 5 and minus 5 degrees at whatever interval you want.

The user only sees the sprite pointing in the direction you last pointed it within the frame.

Alternatively keep it in one script to ensure the wobble is always even since there's a chance the above will show a bias towards wobbling in one direction. Let's say you want the wobble direction to change every two frames. Use something like this.

setframecountto0setwobble-dirto5repeatuntilpointindirectionsaved-dirmove5stepschangeframecountby1turnwobble-dirdegreesifframecount=2thensetframecountto0setwobble-dirto-1*wobble-dir eg until touching object or touching bullet

Obviously you can include a check for touching the bullet in the same loop.

Powered by DjangoBB