Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Posts: 1,483Member
edited March 2016

I cant figure out whats useful about using the magnitude function in a platformer game.

For example
To calculate a distance between a player and an enemy i can put this rule.
in the enemy actor - if game.playerX is > self.position.x-100 and if game.playerX is < self.position.x+100 then display text

its the same as constraining magnitude to calculate the distance between player and an enemy and then adding a rule to display text. why constrain instead of using a simple rule, does it work different ?

thank you

• Posts: 8,959Member, Sous Chef, PRO, Bowlboy Sidekick
edited March 2016

Having a hard time understanding what you're trying to ask.

You use the constrain behavior to constantly update the value outputted by the magnitude function. You want to do this so you can always evaluate the distance between two things. If you only evaluate the magnitude function once, the rule may not fire if the magnitude function doesn't meet the rule condition(s).

• London, UK.Posts: 12,822Member

@Icebox said:
its the same as constraining magnitude to calculate the distance between player and an enemy and then adding a rule to display text.

Your example (if player X> self.position.x-100 . . .) only works in 1 dimension, along the X axis, Magnitude works in 2 dimensions.

@Icebox said:
why constrain instead of using a simple rule, does it work different ?

I think you are conflating a bunch of unrelated things here, Constrain, Magnitude, Rules, Display Text, they all have separate and unrelated functions . . . .

• Posts: 1,483Member
edited March 2016

For example if i want to display text at a certain distance between a player and enemy i can do it this way

if game.playerX is > self.position.x-100 and if game.playerX is < self.position.x+100 then display text

But by using magnitude , I will create a self.distance attribute and constrain it to magnitude(self.positionx - game.playerx , self.positiony - game.playery)

and then add a rule if distance is less than 100 display text.

So this is what i dont understand. I hope im making sense here

• Posts: 1,483Member

@Socks said:
I think you are conflating a bunch of unrelated things here, Constrain, Magnitude, Rules, Display Text, they all have separate and unrelated functions . . . .

Yea i was just giving an example of displaying text when player is close to an enemy. I wanted to be as clear as possible with my question

• London, UK.Posts: 12,822Member

@Icebox said:

@Socks said:
I think you are conflating a bunch of unrelated things here, Constrain, Magnitude, Rules, Display Text, they all have separate and unrelated functions . . . .

Yea i was just giving an example of displaying text when player is close to an enemy. I wanted to be as clear as possible with my question

Yeah, but you are comparing two different things, on one hand you have a function that says if something is larger than or smaller than . . . and on the other hand you have a function that says if magnitude is . . .

But with the magnitude function you are, for some reason, adding a bunch of other stuff (a new attribute, a constrain behaviour, a rule . . .) which makes the comparison sort of irrelevant as you are no longer comparing two comparable functions.

• Posts: 1,483Member

@Socks Magnitude calculates the distance between two actors right ? , and by calculating the distance between 2 actors you are going to use that distance to force a behavior.

So what i was thinking is why would u calculate the distance using magnitude , if you can calculate the distance using a simple condition.

but as you said my example only works in 1 dimension, along the X axis, Magnitude works in 2 dimensions.

So this is what i was missing , thanks . ( I cant explain it further )

• London, UK.Posts: 12,822Member

@Icebox said:

So what i was thinking is why would u calculate the distance using magnitude , if you can calculate the distance using a simple condition.

Well that's kind of my point . . . Magnitude is a simple condition !

I think the reason it appears more complicated than your [less than / more than] example is that you are weighing it down with a bunch of unneeded attributes and constrains and rules . . . and once all this extraneous stuff has been added then making a judgement about which is the more simple route . . but there's no need to constrain magnitude to a 'distance' attribute, or make another rule, any more than there would be to constrain the [less than / more than] version to a 'distance' attribute . . .etc.

Hope that makes sense !

• Posts: 1,483Member

@Socks said:

but there's no need to constrain magnitude to a 'distance' attribute, or make another rule, any more than there would be to constrain the [less than / more than] version to a 'distance' attribute . . .etc.

Yes this is where i was confused , i thought the only way to use magnitude is by constraining so you can always keep it updated and add distance attribute. Now i get what you mean, thanks alot.

• London, UK.Posts: 12,822Member

@Icebox said:
Yes this is where i was confused , i thought the only way to use magnitude is by constraining so you can always keep it updated and add distance attribute. Now i get what you mean, thanks alot.

Yeah, no need to constrain magnitude, use it like any other function, so a better comparison between the two approaches would be:

if game.playerX is > self.position.x-100 and if game.playerX is < self.position.x+100 then display text

Vs . . . .

if magnitude (game.playerX-self.position.x,game.playerY-self.position.Y) <100 then display text

• Posts: 1,483Member

@Socks thats good to know this makes things easier, thanks