Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Stop player movement when touching and edge
- FidJacome
- Scratcher
4 posts
Stop player movement when touching and edge
Hi! <3
I'm trying to make a script that stops the player movement, I already tried a few things to do this, but it always generates a glitch, the controls works with the next script:
(Same with the left side)
Is there anyway to do this?? Any help is welcome.
PD: I'm sorry if there is something wrong with the explanation, it's my first time doing a post, I'll try to fix any mistakes here the fastest I can.
I'm trying to make a script that stops the player movement, I already tried a few things to do this, but it always generates a glitch, the controls works with the next script:
when backdrop switches to [backdrop3 v]
forever
if <key [d v] pressed?> then
change x by (5)
end
end
(Same with the left side)
Is there anyway to do this?? Any help is welcome.
PD: I'm sorry if there is something wrong with the explanation, it's my first time doing a post, I'll try to fix any mistakes here the fastest I can.
- orangetheory
- Scratcher
500+ posts
Stop player movement when touching and edge
Easy
You choose the movement, but the if touching edge part stops the script if the sprite is touching the edge.
when green flag clicked
forever
if <touching [edge v] ?> then
stop [this script v]
end
if <key [right arrow v] pressed?> then
change x by (5)
end
if <key [left arrow v] pressed?> then
change x by (-5)
end
end
You choose the movement, but the if touching edge part stops the script if the sprite is touching the edge.
-Frisbee- -Cricket--Basketball--Forums--Mapping--Coding--Trigonometry master--Mathematics King--Future Prime Minister--Intro-Maker-
I know HTML/CSS, and JavaScript, and with these coding skills I have made some decent projects! Test them out below!
~Archery~Cops + Robbers~
Want an intro, outro, music, effects, or more? Check out the intro shop!
The forum helpers, a place where we help people in the forums
- souleymane2
- Scratcher
100+ posts
Stop player movement when touching and edge
This is a script that will work with collision with walls or anything:
when green flag clicked
forever
if <key [w] pressed?> then
Try to move by (0) (5)
end
if <key [a] pressed?> then
Try to move by (-5) (0)
end
if <key [s] pressed?> then
Try to move by (0) (-5)
end
if <key [w] pressed?> then
Try to move by (5) (0)
end
end
define Try to move by (x) (y)(collision detected is whatever you want to detect collision so it could be touching map, touching edge or both.
change x by (x)
if <collision detected> then
change x by ((0) - (x))
end
change y by (y)
if <collision detected> then
change y by ((0) - (y))
end
just some weird old canadian doing weird old canadian stuff…
- orangetheory
- Scratcher
500+ posts
Stop player movement when touching and edge
~snip~
I think he/she meant to STOP the player from moving when touching the edge, not continue moving after you've touched it, and I don't hink they meant collisions against walls, either.
-Frisbee- -Cricket--Basketball--Forums--Mapping--Coding--Trigonometry master--Mathematics King--Future Prime Minister--Intro-Maker-
I know HTML/CSS, and JavaScript, and with these coding skills I have made some decent projects! Test them out below!
~Archery~Cops + Robbers~
Want an intro, outro, music, effects, or more? Check out the intro shop!
The forum helpers, a place where we help people in the forums
- FidJacome
- Scratcher
4 posts
Stop player movement when touching and edge
~snip~
I think he/she meant to STOP the player from moving when touching the edge, not continue moving after you've touched it, and I don't hink they meant collisions against walls, either.
I think I did not explain it very well, I actually meant that I wanted to stop the movement to, for example the left side if it's touching the left edge, but that the player can still move to the right side, and if stop touching the edge he can move to the left side again, basically make the edges some kind of barriers
- zebrastripesagain
- Scratcher
100+ posts
Stop player movement when touching and edge
Hi, I think I can help!
Use this script:
Hope that helped!
Use this script:
forever
if <touching [edge] ?> then
stop [this script]
end
end
Hope that helped!
_________ ׂׂૢ་༘࿐୨⎯ “Zebra” ⎯୧
┊ ➶ 。˚ ° Artist & Game Maker ⇙
┆ ° ♡ • ➵ ✩ ◛ °⇢ ˗ˏˋ Empath, Hufflepuff ࿐ྂ
·˚ ༘₊· ͟͟͞͞꒰➳˗ˏˋYou matter so muchˊˎ˗ ↴
↳˳;; ❝Racing -ScratchDesign- to 1.5kᵕ̈೫˚∗
○Join my 1k tournament!○ ○Read this message○
- 290Scratcher
- Scratcher
1000+ posts
Stop player movement when touching and edge
Do you mean to make this a game over or to make the edge a sort of wall?
This is my forum signature, here it's okay to… forget it, you've probably seen hundreds of these signatures before.
https://youtu.be/dQw4w9WgXcQ <— Click this funny and not suspicious link to get Scratch 4 early!
Joined at the age of 8 and somehow I'm still alive and decently semi-active on the forums.
(Reminder to take care of yourself and stay safe, the world is wild after all)
https://ecosia.org it's good trust me
- FidJacome
- Scratcher
4 posts
Stop player movement when touching and edge
I meant making the edge a wall Do you mean to make this a game over or to make the edge a sort of wall?
- FidJacome
- Scratcher
4 posts
Stop player movement when touching and edge
This is a script that will work with collision with walls or anything:when green flag clicked
forever
if <key [w] pressed?> then
Try to move by (0) (5)
end
if <key [a] pressed?> then
Try to move by (-5) (0)
end
if <key [s] pressed?> then
Try to move by (0) (-5)
end
if <key [w] pressed?> then
Try to move by (5) (0)
end
enddefine Try to move by (x) (y)(collision detected is whatever you want to detect collision so it could be touching map, touching edge or both.
change x by (x)
if <collision detected> then
change x by ((0) - (x))
end
change y by (y)
if <collision detected> then
change y by ((0) - (y))
end
Thanks!
- Discussion Forums
- » Help with Scripts
- » Stop player movement when touching and edge