Discuss Scratch

windows-11-pro
Scratcher
100+ posts

The player couldn't be pushed backwards when an enemy touches it

Help!
I've been trying to make the player got pushed when touches an enemy, and here's the code I tried:
when I start as a clone
show
set size to (pick random (100) to (200))%
if <(size) < [150]> then
set [hitpoints v] to [2]
else
set [hitpoints v] to [4]
end
repeat until <(hitpoints) = [0]>
move ((2) - ((touching [Box v]) ? (1.5) : (0))) steps
point towards [Player v]
if <touching [Bullet v]> then
change [hitpoints v] by (-1)
move (-4) steps
set (brightness v) effect to (50)
wait (0) secs
clear graphic effects
end
if <touching [Player v]> then
change (health v) by (-1)
set (dmgpos v) to ((direction) * (-1))
broadcast [Ouch v]
wait until <not <touching (Player v) ?>>
end
end
delete this clone
and the player's script:
when I receive [Ouch v]
point in direction (dmgpos)
move (40) steps

please help me!

Last edited by windows-11-pro (March 30, 2024 12:01:36)




windows-11-pro

I make very cool games!!!!!

My games:
(Click the pictures to play the game!)






Please play my game it deserves attention (Not tiles 2 it has 8000 views)
MrKingofScratch
Scratcher
100+ posts

The player couldn't be pushed backwards when an enemy touches it

Make sure that the dmgpos variable is for all sprites

Does the player turn at all or anything like that? If you have the player always pointing towards the mouse, than it might point back towards the mouse before the move steps block can be performed.

It would help a lot if you shared the project.

Last edited by MrKingofScratch (March 28, 2024 15:09:40)


Last edited by kaj (Tomorrow 00:00:00)
100th post!
MKYCATS2
Scratcher
80 posts

The player couldn't be pushed backwards when an enemy touches it

is the enemy a different sprite? if so, make it instead of
point in direction (dmgpos)
you should make it
point towards [enemy v]
turn cw (180) degrees
move (40) steps
or you could also do this
point towards [enemy v]
move (-40) steps
and, I see the problem as well. you have the “delete clone” block in the repeat until block. it needs to be outside the repeat until block.
MrKingofScratch
Scratcher
100+ posts

The player couldn't be pushed backwards when an enemy touches it

MKYCATS2 wrote:

is the enemy a different sprite? if so, make it instead of
point in direction (dmgpos)
you should make it
point towards [enemy v]
turn cw (180) degrees
move (40) steps
or you could also do this
point towards [enemy v]
move (-40) steps
and, I see the problem as well. you have the “delete clone” block in the repeat until block. it needs to be outside the repeat until block.

This wouldn't work when using clones for enemies

Last edited by kaj (Tomorrow 00:00:00)
100th post!
MKYCATS2
Scratcher
80 posts

The player couldn't be pushed backwards when an enemy touches it

i got nothing for you then sry
windows-11-pro
Scratcher
100+ posts

The player couldn't be pushed backwards when an enemy touches it

MrKingofScratch wrote:

(#2)
Make sure that the dmgpos variable is for all sprites

Does the player turn at all or anything like that? If you have the player always pointing towards the mouse, than it might point back towards the mouse before the move steps block can be performed.

It would help a lot if you shared the project.

i'm sorry my project is an sb3 and i will not upload it



windows-11-pro

I make very cool games!!!!!

My games:
(Click the pictures to play the game!)






Please play my game it deserves attention (Not tiles 2 it has 8000 views)
windows-11-pro
Scratcher
100+ posts

The player couldn't be pushed backwards when an enemy touches it

bump



windows-11-pro

I make very cool games!!!!!

My games:
(Click the pictures to play the game!)






Please play my game it deserves attention (Not tiles 2 it has 8000 views)

Powered by DjangoBB