The Mugen Fighters Guild

Help => M.U.G.E.N Development Help => Topic started by: altoiddealer on December 28, 2014, 09:02:16 pm

Title: Scale P2 to specific pixel size
Post by: altoiddealer on December 28, 2014, 09:02:16 pm
For part of a super move I am working on, I want to make P2 get scaled down to about 20px, regardless of how big or small the character is.

I'm guessing it's impossible to get an exact size, but for my purpose a rough estimate will suffice.


In P2's custom state, I have these State Controllers:

Code:
[State 3301, 1]
type = AngleDraw
triggerall = Const(size.height) > ((Const(size.ground.back) + Const(size.ground.front)))
trigger1 = anim = 0
trigger2 = anim = 20
Scale = (20/Const(size.height)),(20/Const(size.height))

[State 3301, 1]
type = AngleDraw
triggerall = Const(size.height) < ((Const(size.ground.back) + Const(size.ground.front)))
trigger1 = anim = 0
trigger2 = anim = 20
Scale = (20/(Const(size.ground.back) + Const(size.ground.front))),(20/(Const(size.ground.back) + Const(size.ground.front)))

Unfortunately, this doesn't work  :knife:  I'm assuming it would work, but it's just not doing the math for the "Scale" parameter.  I tested by removing the math and changing P2's Constant Height to "2," and he is drawn at 2x size.  I also understand that there are other factors I will need to take into consideration, such as P2's Const(size.xscale) and Const(size.yscale)

...Is there a workaround, or another method, to achieve this?

Many thanks in advance

**EDIT** Is there any way to set this calculation as a var, and have it recognized by P2 in the custom state?  I've tried all the redirections I can think of without success, and can't find anything about it through Google
Title: Re: Scale P2 to specific pixel size
Post by: Алексей on December 29, 2014, 03:46:04 pm
Your logic should work here. One thing you have to understand about mugen is that if no floating point (float) numbers are within an equation, the result will be an integer. I can't remember if you need both the numerator and denominator as floats, but it doesn't hurt to make both:
Code:
Scale = (20.0/Const(size.height)*1.0),(20.0/Const(size.height)*1.0)

Quote
**EDIT** Is there any way to set this calculation as a var, and have it recognized by P2 in the custom state?  I've tried all the redirections I can think of without success, and can't find anything about it through Google
It's actually better that you don't in this case. While you can read vars from the enemy, in a custom state "var(0)" refers to the var of P1, not P2. Making changes to player vars within custom states is frowned upon because it can cause strange issues with code from the player's State -2 that you couldn't be aware of on a per-character basis. However, there is one way that you can have the player in your custom state read a "variable" of yours. It works like this:
In the HitDef, you take one of the unused (in your particular case) parameters and set it to whatever you want. For example:
Code:
fall.envshake.time = 0 ; To disable the fall.envshake entirely.
fall.envshake.freq = (20.0/enemynear(0),Const(size.height)*1.0)

Then in your custom state, you would access the "variable" using GetHitVar:
Code:
scale = GetHitVar(fall.envshake.freq)
Title: Re: Scale P2 to specific pixel size
Post by: altoiddealer on December 29, 2014, 04:24:04 pm
Your logic should work here. One thing you have to understand about mugen is that if no floating point (float) numbers are within an equation, the result will be an integer. I can't remember if you need both the numerator and denominator as floats, but it doesn't hurt to make both:
Code:
Scale = (20.0/Const(size.height)*1.0),(20.0/Const(size.height)*1.0)

Hmm... I understand!  I'll give this a shot when I get home from work.  Thanks man, I'd never think of this.


However, there is one way that you can have the player in your custom state read a "variable" of yours. It works like this:
In the HitDef, you take one of the unused (in your particular case) parameters and set it to whatever you want. For example:
Code:
fall.envshake.time = 0 ; To disable the fall.envshake entirely.
fall.envshake.freq = (20.0/enemynear(0),Const(size.height)*1.0)

Then in your custom state, you would access the "variable" using GetHitVar:
Code:
scale = GetHitVar(fall.envshake.freq)


Mind = Blown.  ._.

I know not to try setting/changnig vars within a custom state, but I've been racking my brain, and searching high and low on Google, on how the hell to read P1's vars from within a custom state.  This is awesome information right here.  Too bad you can't detect a Var if it changes after P2 is put into the custom state... but I think this will be useful to simplify the coding for my custom Win Pose which controls P2.
Title: Re: Scale P2 to specific pixel size
Post by: Алексей on December 29, 2014, 04:31:03 pm
Hmm... I understand!  I'll give this a shot when I get home from work.  Thanks man, I'd never think of this.
Haha, no problem. :D

Mind = Blown.  ._.

I know not to try setting/changing vars within a custom state, but I've been racking my brain, and searching high and low on Google, on how the hell to read P1's vars from within a custom state.  This is awesome information right here.
Oh yeah man. I was equally surprised when I found out about this. :) I can't take credit for it though. I believe it was Cyanide who I first saw this from.
Title: Re: Scale P2 to specific pixel size
Post by: altoiddealer on December 29, 2014, 06:43:30 pm
It worked!  :buttrox:

However, I noticed that the height constant seems to be set low (at least for KFM) because (I think) it's really just used to determine how high the other player needs to jump to get over you.

So I'm factoring midposy X2 instead, because that seems to be slightly more accurate.

Finished code I'm using:

Code:
[State 3301, 1] ;P2 is more tall than wide
type = AngleDraw
triggerall = (Const(size.mid.pos.y)*-2.0) > ((Const(size.ground.back) + Const(size.ground.front)))
trigger1 = anim = 0
trigger2 = anim = 20
trigger3 = anim = 3306
Scale = (18.0/(Const(size.mid.pos.y)*-2.0)),(18.0/(Const(size.mid.pos.y)*-2.0))

[State 3301, 2]
type = AngleDraw ;P2 is more wide than tall
triggerall = (Const(size.mid.pos.y)*-2.0) < ((Const(size.ground.back) + Const(size.ground.front)))
trigger1 = anim = 0
trigger2 = anim = 20
trigger3 = anim = 3306
Scale = 18.0/(Const(size.ground.back) + Const(size.ground.front)),18.0/(Const(size.ground.back) + Const(size.ground.front))