This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-06-04 16:58:37

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Going through walls glitch

I have a game called Zombie Defense.  In One Player mode, the player points toward the mouse.  If it touches a wall, it moves -5 steps.  Sometimes, it goes through walls.  Any help here?


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#2 2012-06-04 17:01:21

fetzer
Scratcher
Registered: 2009-06-11
Posts: 70

Re: Going through walls glitch

Can you post project so i may look at how you did?

Offline

 

#3 2012-06-04 17:04:30

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Going through walls glitch

I did.  Check my profile.


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#4 2012-06-04 17:12:38

fetzer
Scratcher
Registered: 2009-06-11
Posts: 70

Re: Going through walls glitch

Hmmm, the move back -5 steps thing..... i would put a invisible barrior around the building, that you can shoot through but they cant go past

Offline

 

#5 2012-06-04 17:19:22

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Going through walls glitch

Doing wall detection in this circumstance is difficult, as you basically have to go through walls if the mouse is in the right place.  You could change x and y velocities based on the mouse position, which would make walls a lot easier to program.  Is this a viable option?


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#6 2012-06-04 17:37:23

fetzer
Scratcher
Registered: 2009-06-11
Posts: 70

Re: Going through walls glitch

Ya, i might also suggest making the wall a bit thicker?

Offline

 

#7 2012-06-04 17:38:14

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: Going through walls glitch

make sure you're not going faster than the width of the wall. Otherwise you will go through the walls.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#8 2012-06-04 17:46:06

fetzer
Scratcher
Registered: 2009-06-11
Posts: 70

Re: Going through walls glitch

Can someone answer my Gravity question?

Offline

 

#9 2012-06-04 19:37:39

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Going through walls glitch

joefarebrother wrote:

make sure you're not going faster than the width of the wall. Otherwise you will go through the walls.

The problem isn't wall thickness (at least, not directly), since the position of the sprite is directly related to the position of the mouse.  The ball isn't really "moving" in the traditional sense, but rather "teleporting" to a point, regardless of whether walls lie between that point and its previous point.  You'll either have to check along the path the ball travels (fairly complicated) or work with some kind of velocity script (less complicated, but I wouldn't say "easy").


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#10 2012-06-05 13:41:54

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Going through walls glitch

MoreGamesNow wrote:

joefarebrother wrote:

make sure you're not going faster than the width of the wall. Otherwise you will go through the walls.

The problem isn't wall thickness (at least, not directly), since the position of the sprite is directly related to the position of the mouse.  The ball isn't really "moving" in the traditional sense, but rather "teleporting" to a point, regardless of whether walls lie between that point and its previous point.  You'll either have to check along the path the ball travels (fairly complicated) or work with some kind of velocity script (less complicated, but I wouldn't say "easy").

It's a badly painted person from sky view...  Anyways, your right...


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#11 2012-06-09 22:14:58

lalala3
Scratcher
Registered: 2008-10-03
Posts: 100+

Re: Going through walls glitch

The problem is that you made it move away from the mouse, not the wall.


http://img515.imageshack.us/img515/9374/signature2nt.png

Offline

 

#12 2012-06-10 19:05:04

Randomness_Player
Scratcher
Registered: 2012-06-06
Posts: 20

Re: Going through walls glitch

Did you use color sensing or sprite sensing?
Try using sprite sensing as the wall...

lalala3 is quite right... because the mouse pointer is black... and you might have used color sensing.

Offline

 

#13 2012-06-10 20:06:36

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Going through walls glitch

MoreGamesNow wrote:

joefarebrother wrote:

make sure you're not going faster than the width of the wall. Otherwise you will go through the walls.

The problem isn't wall thickness (at least, not directly), since the position of the sprite is directly related to the position of the mouse.  The ball isn't really "moving" in the traditional sense, but rather "teleporting" to a point, regardless of whether walls lie between that point and its previous point.  You'll either have to check along the path the ball travels (fairly complicated) or work with some kind of velocity script (less complicated, but I wouldn't say "easy").

What you could do: instead of going directly to the inverse of mouse x and mouse y, as MoreGamesNow pointed out, store those values in variables ("destination x" and "destination y", for example).  The player attempts to move to that location at a steady speed.  If he can't get there (he runs into a wall), he backs up.  This is more of the "check along the path the ball travels" method, but that should do it.  This is probably easier than a velocity method (in my opinion).  That being said, I don't really like working with Scratch direction in the first place, so I end up using velocity anyway.

Last edited by amcerbu (2012-06-10 20:09:06)

Offline

 

#14 2012-06-10 20:40:30

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Going through walls glitch

This script should work "better".  Increasing the number of trials (increase "5" and the if-else statements) will make it "better", but at the cost of speed.  I don't want to guess whether it will fit into a single frame, but, at the very least, the script should show the basic concept.

when gf clicked
forever
set [m_x v] to (mouse x)
set [m_y v] to (mouse y)
set [x v] to (x position)
set [y v] to (y position)
set [d v] to ((distance to [mouse-pointer v])/(5))
point towards [mouse-pointer v]
move (d) steps
if<touching [wall v]?>
go to x:(x) y:(y)
else
set [x v] to (x position)
set [y v] to (y position)
move (d) steps
if<touching [wall v]?>
go to x:(x) y:(y)
else
set [x v] to (x position)
set [y v] to (y position)
move (d) steps
if<touching [wall v]?>
go to x:(x) y:(y)
else
set [x v] to (x position)
set [y v] to (y position)
move (d) steps
if<touching [wall v]?>
go to x:(x) y:(y)
else
set [x v] to (x position)
set [y v] to (y position)
move (d) steps
if<touching [wall v]?>
go to x:(x) y:(y)
end
end
end
end
end


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#15 2012-06-11 11:37:16

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Going through walls glitch

^^ That should work.  Hooray for awkward Scratch programming to achieve speed and precision!

Offline

 

#16 2012-06-11 12:57:20

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: Going through walls glitch

amcerbu wrote:

^^ That should work.  Hooray for awkward Scratch programming to achieve speed and precision!

I don't find that awkward. To me it's quite normal.  hmm

Yeah, it should work.  wink


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&amp;display=small

Offline

 

#17 2012-06-11 15:49:52

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Going through walls glitch

Well, if Scratch had greater computational speed (in other words, no built-in delay), I would use a recursive function, but unfortunately, loops are slow.

Last edited by amcerbu (2012-06-11 15:49:59)

Offline

 

#18 2012-06-14 13:43:21

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Going through walls glitch

I like simpler programs though... My personality is "try to find the easiest way to get the best achievement possible."   tongue


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#19 2012-06-15 18:10:47

wade32
New Scratcher
Registered: 2012-06-15
Posts: 4

Re: Going through walls glitch

This looks good to me..

Offline

 

#20 2012-06-15 18:12:56

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Going through walls glitch

It doesn't to me, though.  Any simpler scripts?  I'm making the project with my friend and he is a beginner.


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#21 2012-06-15 22:53:42

Garr8
Scratcher
Registered: 2011-08-10
Posts: 1000+

Re: Going through walls glitch

I had the same problem with my pong game for getting the ball to land on the paddle, i looked up the examples and figured it out.


What I scored on Pokemon Quiz: Porygon

Offline

 

#22 2012-06-16 07:56:46

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Going through walls glitch

This may be simpler.

when gf clicked
forever
set [d v] to ((distance to [mouse-pointer v])/(length of sprite))
point towards [mouse-pointer v]
set[bool v] to [false]
set [x v] to (x position)
set [y v] to (y position)
repeat until <<(distance to [mouse-pointer v]) < (length of sprite)> or <(bool) = [true] >>
broadcast [check v] and wait
end
go to x:(mouse x) y: (mouse y)
if <touching [wall v]?>
go to x:(x) y:(y)
end

When I Receive [check v]
move (d) steps
if<touching [wall v]?>
go to x:(x) y:(y)
set [bool v] to [true]
else
set [x v] to (x position)
set [y v] to (y position)
end
P.S. 1,300th post!

Last edited by MoreGamesNow (2012-06-16 07:58:06)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#23 2012-06-16 09:29:25

EPICPIKAGUY
Scratcher
Registered: 2011-05-17
Posts: 22

Re: Going through walls glitch

fetzer wrote:

Ya, i might also suggest making the wall a bit thicker?

Yep,that is a great idea,but what if u wanna make a wall thin?first you have to make a maximum velocity(your caracter cannot go faster than a certain speed),then make your sensor as thick as your maximum velocity(e.g. Max vel. Equals 5,u make sensor 5 pixels(if u don't know that measure,just estimate)).


file:///C:/Documents%20and%20Settings/Ethan/Desktop/798330_sm.gif

Offline

 

#24 2012-06-16 09:30:47

EPICPIKAGUY
Scratcher
Registered: 2011-05-17
Posts: 22

Re: Going through walls glitch

EPICPIKAGUY wrote:

fetzer wrote:

Ya, i might also suggest making the wall a bit thicker?

Yep,that is a great idea,but what if u wanna make a wall thin?first you have to make a maximum velocity(your caracter cannot go faster than a certain speed),then make your sensor as thick as your maximum velocity(e.g. Max vel. Equals 5,u make sensor 5 pixels(if u don't know that measure,just estimate)).

No offense,of corse!


file:///C:/Documents%20and%20Settings/Ethan/Desktop/798330_sm.gif

Offline

 

#25 2012-06-16 10:26:27

laser314
Scratcher
Registered: 2010-07-16
Posts: 100+

Re: Going through walls glitch

amcerbu wrote:

Well, if Scratch had greater computational speed (in other words, no built-in delay), I would use a recursive function, but unfortunately, loops are slow.

I don't think turbo mode has the delay.


http://alpha.scratch.mit.edu/scratchr2/static//images/logo_sm.png 2.0 Alpha Tester!http://i49.tinypic.com/1zckcqb.png

Offline

 

Board footer