YesNoOk
avatar

Turn (SCTRLs) (Read 6049 times)

Started by Ricepigeon, September 17, 2015, 08:06:05 PM
Share this topic:
Turn (SCTRLs)
#1  September 17, 2015, 08:06:05 PM
  • *****
  • Gaps? Where we're going, we don't need gaps...
    • USA
    • ricepigeon.neocities.org
Instantly turns the player to face the opposite direction. Does not play a turning animation.

Required parameters:
    none
Optional parameters:
    none
Example:
    none

Additional Notes:
If the Turn SCTRL is triggered while the Player's horizontal (X) velocity is non-zero, the direction of the Player's original trajectory will be preserved after turning unless another VelSet SCTRL is applied (i.e.: Player1 is facing and moving toward the right side of the screen, then turns to face left while still moving towards the right).
Last Edit: September 18, 2015, 02:47:36 PM by Just No Point
Re: Turn (SCTRLs)
#2  September 20, 2015, 04:31:46 PM
  • ****
  • stillRetired.
  • Formerly Known As Genesis
    • USA
    • www.mediafire.com/folder/7j1slkpa7lm0w/Public_Works
I know mugen's default turning is hardcoded but could you use this and noautoturn to override it? What would be the optimal trigger if so?
Re: Turn (SCTRLs)
New #3  November 28, 2020, 02:36:16 AM
  • ***
  • Non est hoc propter hoc sed propter est hoc
    • USA
    • doubletrend-zeta.neocities.org/
I know mugen's default turning is hardcoded but could you use this and noautoturn to override it? What would be the optimal trigger if so?
Though it's been a while, this is a helpful question to provide an answer to. This solution seems effective, though I don't doubt there might be a better one.

Taking a look at this example, if you wanted to code a redirect move you can prevent autoturn in the custom state, but not in your own common, with an assertspecial flag.

This is simply because the common uses a changeanim, not a changestate, for all turning actions:

Code:
[Statedef 0]
type = S
physics = S
sprpriority = 0

[State 0, 1]
type = ChangeAnim
trigger1 = Anim != 0 && Anim != 5
trigger2 = Anim = 5 && AnimTime = 0;Turn anim over
value = 0

trigger1 determines that if the animation that's carried over from the previous state is neither 0 nor 5, then it becomes 0
trigger2 determines that if anim 5 is playing and returns you to anim 0 when it's over

The result from that first example is the common trying to figure out where you're facing and then freaking out:




It is hardcoded, and in a way that requires multiple triggers to override everything.

What you will do is determine a variable in your redirection state ahead of time, like at time=0 or whatever you like. For me this is var(15), which equals 2 only because I'm using a floating assigner variable to save space. The stateno I'm working with is 850, but it can be whatever you wish.
After this you have to use three triggers in state 0 in your common (or an overwritten state 0 if you don't like working with a custom common):

This changeanim will be used to override the vanilla changeanim by confirming your variable is true, and the animelemtime(1)=0 will attempt to correct the turning immediately.
Code:

[State turn override]
type = ChangeAnim
triggerall = var(15)=2 && prevstateno =850
trigger1 = Anim != 0 && Anim != 5
trigger2 = Anim = 5 && Animelemtime(1)=0;Turn anim over
value = 0
However, this will still give you a slight jitter as the first tick of the first frame of the turn animation will play; therefore, the turn here will act to override any sort of freaking out by flipping it immediately at time=0, the same time as the Animelemtime(1)=0. The assertspecial is helpful as a failsafe.
Code:
[State 0, AssertSpecial]
type = AssertSpecial
triggerall = var(15)=2 && prevstateno =850
trigger1 = time=0
flag = Noautoturn

[State 0, Turn]
type = Turn
triggerall = var(15)=2 && prevstateno =850
trigger1 = time=0

Here's the result.

EDIT:
forgot to mention that you should update the original turn changeanim to make sure your variable isn't on, here's the full state too (with some quick fixes)
Code:
; Stand
[Statedef 0]
type = S
physics = S
sprpriority = 0

[State 0, AssertSpecial] ;no forced turn by mugen
type = AssertSpecial
triggerall = var(15)=2 && prevstateno =850
trigger1 = time=0
flag = Noautoturn

[State 0, Turn] ;corrective turn for first frame of anim 5
type = Turn
triggerall = var(15)=2 && prevstateno =850
trigger1 = time=0

[State turn override] ;override anim 5 at the first frame
type = ChangeAnim
triggerall = var(15)=2 && prevstateno =850
trigger1 = Anim != 0 && Anim != 5
trigger2 = Anim = 5 && Animelemtime(1)=0;Turn anim over
value = 0

[State 0, 1] ;original sctrl with variable exception
type = ChangeAnim
triggerall = var(15)!=2
trigger1 = Anim != 0 && Anim != 5
trigger2 = Anim = 5 && AnimTime = 0;Turn anim over
value = 0

[State 0, VarSet] ;make sure to turn off your redirect variable
type = VarSet
trigger1 = var(15)=2 && time=1 && prevstateno =850
v = 15
value = 0

; the rest as usual
[State 0, 2]
type = VelSet
trigger1 = Time = 0
y = 0

[State 0, 3] ;Stop moving if low velocity or 4 ticks pass
type = VelSet
trigger1 = abs(vel x) < Const(movement.stand.friction.threshold)
trigger2 = Time = 4
x = 0

[State 0, 4] ;Are you dead?
type = ChangeState
trigger1 = !alive
value = 5050
ctrl = 0
Last Edit: November 28, 2020, 04:49:57 AM by Bannana