The Daily Click ::. Forums ::. Klik Coding Help ::. Custom movement problem>>>
 

Post Reply  Post Oekaki 
 

Posted By Message

KevinHaag



Registered
  28/01/2005
Points
  266

VIP Member
26th March, 2005 at 14:47:22 -

I've made a custom movement in which when you press the up, down, left, or right arrow keys, the player moves 40 pixels in that direction; but I cant get the player to detect a collision and stop when it hits an obstacle. Does anyone have any ideas???

 
Image
http://www.kevinhaag.ca

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
26th March, 2005 at 14:59:19 -

ya, fourty pixels is a huge gap, you are not moving it 40 pixels, you are teleporting it 40 pixels. Which means that anything that is within those 40 pixels doesn't get detected.

 
Craps, I'm an old man!

Destroyer (CrobaSoft)



Registered
  10/10/2004
Points
  1106
26th March, 2005 at 14:59:59 -

just use the move safely object

start of frame
(move safely object) set object to player

upon pressing right
(move safely) prepare safey procedure
set x of player to x of player + 40
(move safely) commence safety procedure

upon pressing left
(move safely) prepare safey procedure
set x of player to x of player - 40
(move safely) commence safety procedure

upon pressing up
(move safely) prepare safey procedure
set y of player to y of player - 40
(move safely) commence safety procedure

upon pressing down
(move safely) prepare safey procedure
set y of player to y of player + 40
(move safely) commence safety procedure

on safety
+player overlap a backdrop
---> stop safety procedure

remember it has to be done in that excact order or else it wont work (or you will get a crash)
and you cant use collision, you have to use overlap.

Image Edited by the Author.

 
Visit www.crobasoft.com or you're a Noob.

KevinHaag



Registered
  28/01/2005
Points
  266

VIP Member
26th March, 2005 at 17:27:06 -

I don't get it... it doesn't make any sense... what is a 'move safley' object???

 
Image
http://www.kevinhaag.ca

Destroyer (CrobaSoft)



Registered
  10/10/2004
Points
  1106
26th March, 2005 at 17:32:30 -

it's an extension, you can get it here
http://click.spatang.com/ext/view.php?ext=309

 
Visit www.crobasoft.com or you're a Noob.

KevinHaag



Registered
  28/01/2005
Points
  266

VIP Member
26th March, 2005 at 19:31:54 -

I cant do that... I'm using TGF and that extension is for MMF!
Do you got any other ideas?

 
Image
http://www.kevinhaag.ca

Destroyer (CrobaSoft)



Registered
  10/10/2004
Points
  1106
26th March, 2005 at 20:03:40 -

then use the fast loop object

upon pressing left
start loop 1 for 40 loops
set alterbate value a to 1

upon pressing right
start loop 1 for 40 loops
set alterbate value a to 2

upon pressing up
start loop 1 for 40 loops
set alterbate value a to 3

upon pressing down
start loop 1 for 40 loops
set alterbate value a to 4



loop trigger 1
+alterbalte value a = 1
set x of player to x of player - 1

loop trigger 1
+alterbalte value a = 2
set x of player to x of player + 1

loop trigger 1
+alterbate value a = 3
set y of player to y of player -1

loop trigger 1
+alterbate value a = 4
set y of player to y of player +1

loop trigger 1
+player overlaps a backdrop
stop loop 1

again the order has to be the same and you have to use overlap.

Image Edited by the Author.

 
Visit www.crobasoft.com or you're a Noob.

KevinHaag



Registered
  28/01/2005
Points
  266

VIP Member
27th March, 2005 at 10:43:09 -

Is that:
Set the "players" alterable value A?

 
Image
http://www.kevinhaag.ca

Destroyer (CrobaSoft)



Registered
  10/10/2004
Points
  1106
27th March, 2005 at 10:55:19 -

yes.
and i made a mistake up there. dont start the loop before you set the alterble value, start it after.

 
Visit www.crobasoft.com or you're a Noob.

KevinHaag



Registered
  28/01/2005
Points
  266

VIP Member
27th March, 2005 at 12:33:08 -

Destroyer:
It didn't work...
What to do what to do???

 
Image
http://www.kevinhaag.ca

AsparagusTrevor

Mine's a pint of the black stuff

Registered
  20/08/2002
Points
  2364

Game of the Week WinnerHas Donated, Thank You!VIP MemberEvil kliker
27th March, 2005 at 13:18:04 -

I don't understand why you'd be moving 40 pixels at once and having an obstacle in between a 40 pixels?

 
Image

clwe



Registered
  17/12/2002
Points
  702
27th March, 2005 at 14:41:38 -

What Destroyer said was pretty much spot-on...though you might want to change it so that each direction starts off using a different fastloop, like so:


upon pressing left
• start loop 1 for 40 loops

upon pressing right
• start loop 2 for 40 loops

upon pressing up
• start loop 3 for 40 loops

upon pressing down
• start loop 4 for 40 loops


loop trigger 1 AND player is not overlapping a backdrop
• set x of player to x of player - 1

loop trigger 2 AND player is not overlapping a backdrop
• set x of player to x of player + 1

loop trigger 3 AND player is not overlapping a backdrop
• set y of player to y of player -1

loop trigger 4 AND player is not overlapping a backdrop
• set y of player to y of player +1


The reason why I say this is because it would allow for the player to move in diagonals when two directions are pressed.

 
n/a

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
27th March, 2005 at 15:11:19 -

Another way to do that which isnt so efficient is to

while pressing up
set y of player to y of player -1

then

while pressing up and overlapping obstacle
set y of player to y of player +1

and you can copy these as much as you like to make it move faster, however 40 times is a little much so maybe you're better of with fastloop.

 
.

KevinHaag



Registered
  28/01/2005
Points
  266

VIP Member
28th March, 2005 at 21:05:08 -

I figured it out!

Upon pressing left arrow
+
[Player] collides with [obstacle]:
-set X of [player] to -40, 0 from [player]

And so on and so on with the other directions... I just altered the X and Y coordinates for each direction.

Thanks anyway for all your guys help!


 
Image
http://www.kevinhaag.ca

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
30th March, 2005 at 03:43:53 -

or you could use detectors.
your tecnique with "bouncing back" with the X/Y pos, andyUK is good though it'll look quite bad when you'll go in and out of the wall repetetively.
why go 40 pixs at one time? in SquareRunner i used counters to count how many pixels it should go. I mean like:

Upon pressing (UP) + counter (Y pos) is 0 + ActiveObj(detector UP) is not overlaping backdrop
-Set counter (Y pos) to -8

Counter (Y pos) is less than 0
-Set pos of (player) to pos of (player)-4
-sub 1 to (Y pos)

and the same for the other directions.
That way it moves 32 pixels in every direction smoothly without overlaping walls.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click