The Daily Click ::. Forums ::. Klik Coding Help ::. Advanced Direction Object
 

Post Reply  Post Oekaki 
 

Posted By Message

lembi2001



Registered
  01/04/2005
Points
  608

VIP MemberIt's-a me, Mario!Wii OwnerI like Aliens!Has Donated, Thank You!PS3 OwnerI am an April Fool
19th November, 2008 at 22:55:56 -

I have a problem that I think might be related to this extension. I have multiple enemies on a scrolling level that use bouncin ball movement until the player gets within 100 pixels of the enemy at which point they look in the direction of the player and move towards them. the problem is that only one of the enemies is doing this the others just bounce around as normal. why is this????

 
n/a

-J-



Registered
  05/10/2008
Points
  228

VIP MemberThe Cake is a Lie
20th November, 2008 at 08:46:44 -

Not sure, usualy these types of problems have something to do with Object Scope, you can find an article by Pixelthief about it here: http://create-games.com/article.asp?id=1942

Hope it helps!

 
n/a ...

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
20th November, 2008 at 09:12:52 -

i doubt it would kill you to use a "box" area, in which case you can just do:

If: PosX(Enemy) < (PosX(Player) + 100)
If: PosX(Enemy) > (PosX(Player) - 100)
If: PosY(Enemy) < (PosY(Player) + 100)
If: PosY(Enemy) > (PosY(Player) - 100)
Then: Make (Enemy) look in direction of (Player)(0,0)

 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

-J-



Registered
  05/10/2008
Points
  228

VIP MemberThe Cake is a Lie
20th November, 2008 at 10:25:20 -

Unless he needed it to be EXACTLY 100 pixels all the time

But I doubt that so yeah, box method is probably the best way to go.

 
n/a ...

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th November, 2008 at 10:52:58 -

use the advanced math object instead

+always
-set an alterable value of the enemy to Abs( "Advanced Math object", Sqrt( "Advanced Math object", Pow( "Advanced Math object", ( X( "enemy" ) - X( "player" ) ), 2 ) + Pow( "Advanced Math object", ( Y( "enemy" ) - Y( "player" ) ), 2 ) ) )

than when that value is under however many pixels away from your player, do whatever you need it to do.

Image Edited by the Author.

 
n/a

lembi2001



Registered
  01/04/2005
Points
  608

VIP MemberIt's-a me, Mario!Wii OwnerI like Aliens!Has Donated, Thank You!PS3 OwnerI am an April Fool
20th November, 2008 at 11:04:30 -

thanks for the responses. i'll try the methods and see which works best.

 
n/a

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
20th November, 2008 at 11:17:25 -

with the square box method, the distance will not always be even, for example if it is exactly 100 pixels horizontally and 100 pixels vertically it will be 100*sqrt(2) pixels away, or 141 pixels.

With the circle distance method, it will always be 100 pixels no matter what (give or take a few because of decimals etc)

So essentially with the square method, it will be moving towards the player sooner than it would if you used a circle method of detection.

 
My signature is never too big!!!

lembi2001



Registered
  01/04/2005
Points
  608

VIP MemberIt's-a me, Mario!Wii OwnerI like Aliens!Has Donated, Thank You!PS3 OwnerI am an April Fool
20th November, 2008 at 17:27:59 -

Fat and Sassy Cecil i can't get your formula to work. I have changed the names to Alien and Player but i get Syntax error

 
n/a

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
20th November, 2008 at 19:24:42 -

yes it will work nicer with the distances, but if you're someone who doesn't have a good history of trigonometry & geometry, its 100x easier to just use the box method.

 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th November, 2008 at 20:02:38 -

sorry the advanced math object for mmf2 doesnt seem to accept its pow function. that was a formula that i had from tgf. dont know why mmf screws it up. i even wrote it from scratch in mmf2 and it gave me the syntax error.

you can do distance like this without an extension.

Sqr( ((X( "enemy" )-X( "player" )) Pow 2)+((Y( "enemy" )-Y( "player" )) Pow 2) )

 
n/a

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
20th November, 2008 at 20:09:29 -

one problem with using that formula, cecil, is that it will not work once you get up to very large numbers, like if you were working with a system that stored X & Y positions at 1000x dimensions, which is a common way to make movements smoother. And when you try to take 4000000^2 (which would be X = 4000, not unreasonable), you get a number so large that the expression editor has an integer overflow, and the results are meaningless tripe. I have a modified little function where it shaves down the significant digits of the input values, applies the distance formula, than multiplies it back up again. Been meaning to turn it into a nifty extension, but well, c++ isn't my bag.

 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th November, 2008 at 20:17:33 -

this should work then

on event
+PosX(Enemy) <= (PosX(Player) + 100)
-PosX(Enemy) >= (PosX(Player) - 100)
-PosY(Enemy) <= (PosY(Player) + 100)
-PosY(Enemy) >= (PosY(Player) - 100)

then
set an alterable value of enemy to Sqr( ((X( "enemy" )-X( "player" )) Pow 2)+((Y( "enemy" )-Y( "player" )) Pow 2) )

there. now the integer wont get overflowed and it uses the box method in order to get the accurate distance.

everybody wins

even though i REALLY DOUBT hes going to get into numbers large enough to cause an integer overflow

Edited by Cecilectomy

 
n/a

lembi2001



Registered
  01/04/2005
Points
  608

VIP MemberIt's-a me, Mario!Wii OwnerI like Aliens!Has Donated, Thank You!PS3 OwnerI am an April Fool
20th November, 2008 at 20:32:34 -

Can anyone help me please..... For some bizarre reason only some of them are actually doing anything when i get near them. the source file is here: http://ab.remake.googlepages.com/Game.zip and is in mmf2. The code is in Alien Movement.

 
n/a

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th November, 2008 at 21:49:41 -

for some reason it doesnt like picking individual aliens

in the event

+alterable value b("alien") < 300

make it

+X position of "alien" > X("player")-300
-X position of "alien" < X("player")+300
-Y position of "alien" > Y("player")-300
-Y position of "alien" < Y("player")+300
-alterable value b("alien") < 300

Edited by Cecilectomy

 
n/a

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th November, 2008 at 22:07:29 -

sorry, i know why its not working. you dont need that extra code either.

dont compare 2 general values. you have to compare directly to alterable value b.

insert a condition click on the enemy and choose compare to alterable value.

otherwise it will mess up the object scope like previously mentioned.

 
n/a

lembi2001



Registered
  01/04/2005
Points
  608

VIP MemberIt's-a me, Mario!Wii OwnerI like Aliens!Has Donated, Thank You!PS3 OwnerI am an April Fool
20th November, 2008 at 22:09:34 -

spot on cecil!! thanks!

 
n/a

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th November, 2008 at 22:40:13 -

no problem.

nice looking game there.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click