The Daily Click ::. Forums ::. Klik Coding Help ::. Starting movement at a give time.
 

Post Reply  Post Oekaki 
 

Posted By Message

Nate Baker



Registered
  19/07/2010
Points
  12
15th January, 2011 at 16:23:05 -

Hi all,

This is my first post, I think, so I'm sorry if this has been covered before but I looked and couldn't find anything that inspired a good solution. want I'm looking for is that when the player object gets to close to a monster it triggers the monster to start moving. What is happening now is the when that the player get close to the last monster they all start moving, and not until then. I know this should be pretty simple but I guess I just don't know how to do it. Thanks for looking and any help with be great.
Image

 
n/a

Benny Lindberg



Registered
  08/11/2010
Points
  54
15th January, 2011 at 17:23:22 -

You could make it so that when the player gets near the enemy, a flag is set to ON, and if flag is ON, movement is initiated.

 
n/a

Duncan

Thelonious Dunc

Registered
  18/05/2002
Points
  552

VIP Member
15th January, 2011 at 17:41:42 -

Hey Nate, shouldn't ALL your XY comparisons be in the loop? These are the bits that will cause object focus issues.

Also maybe the 'spread value' action has to happen before the 'start loop' one... Maybe it doesn't matter at all, someone else will know.

Welcome to TDC

 
n/a

JetpackLover



Registered
  01/03/2007
Points
  212
15th January, 2011 at 17:49:36 -

I remember being told that if you switch the position with the player and the enemy in the code the object focus is able to focus per enemy and not as a group.

Someone will surely be able to explain that better.

 
http://www.invincibletime.com/

Devlog for HD MMF Game Omulus. Check it out because it's gonna be awesome. http://omulus.tumblr.com/

Follow me on the twitters https://twitter.com/JetpackLover


GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
15th January, 2011 at 18:13:30 -

Hey, Nate.

Personally, I believe that using a behavior may be easier than groups for this as spread values are not needed, and it will (probably) be easier to understand and much shorter.

I would do this.


Behavior:

Always Set value "Distance" of object to abs(enemy X Position - Player X Position)

Value "Distance" of object <= 128
- Movement Code



Whats cool about this is that its also easier to give each enemy its own sight-range by creating another alterable value for each individual enemy. We'll call it "Sight" and you will change it to how many pixels you wan't the enemy to be able to "see." - In this case - 128. Just make sure that "Sight" is the same alterable value for EVERY enemy (IE: Alterable Value D) so that it can reference it properly.


Behavior:

Always
Set value "Distance" of object to abs(enemy X Position - Player X Position)

Value "Distance" of object <= Value "Sight" of object
- Movement Code


If you want to get really fancy you could use the distance formula, which will get the distance between two objects in any given direction, rather than only X distance.


Always
Set value "Distance" of object to Sqr((X( "Player" )-X( "Enemy" ))*(X( "Player" )-X( "Enemy" ))+(Y( "Player" )-Y( "Enemy" ))*(Y( "Player" )-Y( "Enemy" )))

Value "Distance" of object <= Value "Sight" of object
- Movement Code


I suck at reading formulas. You can probably find more info in articles around here, but heres the distance formula without the values already plugged in:

sqr((X1-X2)*(X1-X2)+(Y1-Y2)*(Y1-Y2))

This isn't necessary, but you can make the distance formula easier to read by using two more alterable values:

Always

Set Value "X Dist" of Object to (Player X Position - Enemy X Position) * (Player X Position - Enemy X Position)

Set Value "Y Dist" of Object to (Player Y Position - Enemy Y Position) * (Player Y Position - Enemy Y Position)

Set Value "Distance" of Object to sqr(X Dist + Y Dist)


 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
15th January, 2011 at 19:22:24 -

Firstly, you should be spreading the value *before* you start the fastloop. You should also start the fastloop on a new line (MMF2 has some bugs, and this just makes it more stable).

Secondly, you shouldn't even be using a fastloop for this to begin with.

Now, the reason your code doesn't work: you *must not* use "compare two general values" if you have more than one instance of an object, as it will *always* retrieve the value from the newest instance.

eg.
On line 31, you have:
-> X("Player")-X("Baddie") < 0
-> X("Player")-X("Baddie") > -128

You *could* have said:
-> X Position of Baddie > X("Player")
-> X Position of Baddie < X("Player") + 128

Note that you *must* compare the X position of the Baddie to the X position of the Player - not the other way around.

The method Gamester suggested (using an intermediate value) is the best way to go, and that's what you'll end up using most of the time - especially if your conditions are more complex.

However, the code doesn't need to be, and *should not* be in a behavior. That only makes it harder to keep track of your code, prevents you using the event list editor, and takes away control over exactly when to execute the event. I'd strongly recommend you avoid behaviours altogether.

@Gamester: Please don't use the code tag. The line-spacing is ridiculous.

 
n/a

Nate Baker



Registered
  19/07/2010
Points
  12
15th January, 2011 at 20:56:56 -


Originally Posted by Duncan
Hey Nate, shouldn't ALL your XY comparisons be in the loop? These are the bits that will cause object focus issues.

Also maybe the 'spread value' action has to happen before the 'start loop' one... Maybe it doesn't matter at all, someone else will know.

Welcome to TDC



Well that worked, and I'm dumb. I will also look in to some of the other suggestions as well Thanks all.



 
n/a

GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
15th January, 2011 at 21:00:15 -

Yeah I kinda noticed that, but I had to get up.

I have no trouble keeping track of behaviors, as I keep my alterable values and strings true across all enemies and mainly use it for things such as damage addition subtraction etc. The only downside IMO is the fact that you cannot reference a group inside a behavior. Groups also have some selection issues that have to be dealt with with work arounds so I try to avoid them in certain scenarios.



 
n/a
   

Post Reply



 



Advertisement

Worth A Click