Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » The player couldn't be pushed backwards when an enemy touches it
- 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:
please help me!
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 cloneand the player's script:
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
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)
- 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.
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)
- 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]or you could also do this
turn cw (180) degrees
move (40) steps
point towards [enemy v]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.
move (-40) steps
- MrKingofScratch
- Scratcher
100+ posts
The player couldn't be pushed backwards when an enemy touches it
is the enemy a different sprite? if so, make it instead ofpoint in direction (dmgpos)you should make itpoint towards [enemy v]or you could also do this
turn cw (180) degrees
move (40) stepspoint towards [enemy v]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.
move (-40) steps
This wouldn't work when using clones for enemies
- 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
(#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
- Scratcher
100+ posts
- Discussion Forums
- » Help with Scripts
- » The player couldn't be pushed backwards when an enemy touches it