The idea: - To implement a basic bézigon (path made of two or more bezier curves) using mugen script language.Edit due to Val suggestion:a bezier code is a smooth curve calculated from at least three points, using this code you can make your projectile fly smooth curves from position a to position b (good for homing projectiles etc).The code below will generate two quadratics bézier curves with random control points starting at player position and ending out of screen. The child helper will smoothly follow the bézier curves creating a quite nice move. :PThe sources: - http://www.gamedev.net/reference/articles/article888.asp - http://www.gamedev.net/reference/articles/article1584.asp - http://www.wtamu.edu/academic/anns/mps/math/mathlab/col_algebra/col_alg_tut54_bi_theor.htm - http://en.wikipedia.org/wiki/Bernstein_polynomial - http://en.wikipedia.org/wiki/Bezier_curveThe result:Quote;---------------------------------------------------------------------------; Bézier control points helper[Statedef 3510]type = Smovetype= Aphysics = Nvelset = 0,0ctrl = 0anim = 9999SprPriority = 2[State 3510, Generate Point 0]Type = Nulltrigger1 = fvar(2) := 0persistent = 0[State 3510, Generate Point 0]Type = Nulltrigger1 = fvar(3) := pos ypersistent = 0[State 3510, Generate Control points]Type = Nulltrigger1 = (1) || fvar(4) := 160 * random/1000.0 * facing; * ifelse(random < 500, 1, -1)trigger1 = (1) || fvar(5) := -15 -60 * random/1000.0trigger1 = (1) || fvar(6) := 320 * random/1000.0 * facing; * ifelse(random < 500, 1, -1)trigger1 = (1) || fvar(7) := -10 -60 * random/1000.0 + 120 * ifelse(random < 500, 0, 1)trigger1 = (1) || fvar(8) := 320 * random/1000.0 * facing; * ifelse(random < 500, 1, -1)trigger1 = (1) || fvar(9) := -10 -60 * random/1000.0trigger1 = (1) || fvar(10) := 320 * random/1000.0 * facing; * ifelse(random < 500, 1, -1)trigger1 = (1) || fvar(11) := -10 -60 * random/1000.0trigger1 = (1) || fvar(12) := 320 * random/1000.0 * facing; * ifelse(random < 500, 1, -1)trigger1 = (1) || fvar(13) := -15 -60 * random/1000.0 + 120 * ifelse(random < 500, 0, 1)trigger1 = (1) || fvar(14) := (320 + 80 * random/1000.0) * facing; * ifelse(random < 500, 1, -1)trigger1 = (1) || fvar(15) := -240 * random/1000.0persistent = 0;Spawn the helpers[State 3510, Helpers]Type = Helpertrigger1 = time = 0stateno = 3512ownpal = 1id = 3510pos = 0,0[State 3510, DestroySelf]Type = DestroySelftrigger1 = numhelper(3510) = 0;---------------------------------------------------------------------------; Bézier points[Statedef 3512]type = Smovetype= Aphysics = Nvelset = 0,0ctrl = 0anim = 3310SprPriority = 2[State 3512, NoShadow]Type = AssertSpecialtrigger1 = 1flag = noShadow[State 3512, VarSet]Type = VarSettrigger1 = var(1) = 0var(1) = parent, var(0)[State 3512, Control how many steps I had taken]Type = VarAddtrigger1= fvar(11) >= 1.0v = 4value = 1[State 3512, A]Type = VarSettrigger1 = var(0) = 0trigger2 = fvar(11) >= 1.0fvar(10) = 1.0ignorehitpause = 1[State 3512, A]Type = VarSettrigger1 = var(0) = 0trigger2 = fvar(11) >= 1.0fvar(11) = 0.0ignorehitpause = 1[State 3512, Generate Control points]Type = Nulltrigger1 = fvar(11) = 0.0trigger1 = (1) || fvar(2) := ifelse(var(4) = 0, parent, fvar(2), fvar(8))trigger1 = (1) || fvar(3) := ifelse(var(4) = 0, parent, fvar(3), fvar(9))trigger1 = (1) || fvar(4) := parent, fvar(4 + var(4) * 6)trigger1 = (1) || fvar(5) := parent, fvar(5 + var(4) * 6)trigger1 = (1) || fvar(6) := parent, fvar(6 + var(4) * 6)trigger1 = (1) || fvar(7) := parent, fvar(7 + var(4) * 6)trigger1 = (1) || fvar(8) := parent, fvar(8 + var(4) * 6)trigger1 = (1) || fvar(9) := parent, fvar(9 + var(4) * 6)[State 3512, Generate X my offset]Type = varsettrigger1 = 1fvar(0)= fvar(2)*fvar(10)*fvar(10)*fvar(10)+ 3 * fvar(4)*fvar(10)*fvar(10)*fvar(11)ignorehitpause = 1[State 3512, Generate X my offset]Type = varsettrigger1 = 1fvar(0) = fvar(0)+ 3 * fvar(6)*fvar(10)*fvar(11)*fvar(11) + fvar(8)*fvar(11)*fvar(11)*fvar(11)ignorehitpause = 1[State 3512, Generate Y my offset]Type = varsettrigger1 = 1fvar(1)=fvar(3)*fvar(10)*fvar(10)*fvar(10)+ 3 * fvar(5)*fvar(10)*fvar(10)*fvar(11)ignorehitpause = 1[State 3512, Generate Y my offset]Type = varsettrigger1 = 1fvar(1) = fvar(1)+ 3 * fvar(7)*fvar(10)*fvar(11)*fvar(11)+fvar(9)*fvar(11)*fvar(11)*fvar(11)ignorehitpause = 1[State -3, M]Type = VarSettrigger1 = Pos X - (fvar(0) + (parent, pos x)) != 0fvar(12) = -((Pos Y - fvar(1))/(Pos X - (fvar(0) + (parent, pos x)))* facing)[State -3, M] ;There can be no triangle if both points share the same X cordType = VarSettrigger1 = Pos X - (fvar(0) + (parent, pos x)) = 0fvar(12) = 0[State -3, Angle]Type = AngleDrawtrigger1 = 1value = Atan(fvar(12)) * (180.0/Pi) + 180 * ifelse(facing=1,(Pos X - (fvar(0) + (parent, pos x)) > 0),(Pos X - (fvar(0) + (parent, pos x)) < 0))[State 3512, PosSet]Type = PosSettrigger1 = 1x = fvar(0) + (parent, pos x)y = fvar(1)ignorehitpause = 1[State 3512, A]Type = VarAddtrigger1 = 1fv = 10value = -0.02ignorehitpause = 1[State 3512, A]Type = VarAddtrigger1 = 1fv = 11value = 0.02ignorehitpause = 1[State 3512, Pause]Type = Transtrigger1 = 1trans = addignorehitpause = 1[State 3512, DestroySelf]Type = DestroySelftrigger1 = var(4) = 2ignorehitpause = 1How it works:- The mother helper creates several control points, saving them in fvar(4) and onward- Each node iteration requires 4 points (we're using quadratic bézier curves here). For each node bigger than 1, the start point is last node end point- For a path with N nodes, the mother helper needs to generate 4 * N points. In our example the starting point fvar(2), fvar(3) is 0,0.- In the child helper, var(4) represents the number of nodes our path will have- Each control point is made of a set of fvars. Fvars with even numbered indexes represents the X component of the point. Fvars with odd numbered indexes represents the Y component of the point.- The X component of the control point must be adjusted by facing to guarantee that the curve will follow the right direction.- In the child helper, fvar(10) and fvar(11) means the amount of the curve already done in parts of 1.0. They're increased and decrease by a fixed amount which must be a fraction of 1.0. The size of this increment determines how many points it will take to fully iterate a node. To find out the increment, divide 1.0 per the number of points you want to draw in each curve. In our example here we have 50 points (1.0/50 = 0.02)- In the child helper, fvar(10) is always incremented and fvar(11) is always decremented- The child helper destroys itself when he finishs the whole path, saving in var(4) the number of nodes already completed.- The given code computes the angle between the current point and the next one and apply it to the child helper.That's it. If you got any other doubt, ask.Kisses.
Mind fixing all the characters above that got screwed up during the board's UTF-8 conversion a few months ago?Also, "bellow" != "below".And the grammar in this sentence needs correcting:Bia said, October 02, 2005, 08:15:52 pmIn our example where have 50 points (1.0/50 = 0.02)(If you want me to, I'll point out additional grammar and spelling errors to correct. These here were just the ones that seemed most significant.)
It makes a helper follow a smooth path using key points to calculate the missing points...To put it simple, it calculate the points of a bézier curve.
@ eddy : the link provided by Bia here mainly tells you all you need about what Bézier curves are.Why do new cars have so smooth curves ? Just thank Bézier. 8)
QuoteCybaster: the link provided by "Bia"(hehe) here mainly tells you all you need about what Bézier curves are(what the!).........(can't beleive I have 2 read).........OOOOOooooh.I feel all college-educated (hasn't bn 2 college yet)let me see if I get this. (ahem)"This code enables helpers to change their mind(of direction) following U?" ^^^^(or gives the appearance of, grammer grammer)(Olive won't have 2 retrace Popeye's movements)This cod 4 the prog or future chars? WoW (so much work)
damn, either you guys are geniuses from harvard, or I missed out on a couple of things during high school and college, because this is all like trying to read Japanese for me (no offense to Japanese). This just makes me want to go back to college and study all there is about Arithmetic or however you want to call it. I feel left out , lost ???, deceived , misguided , time wasted , stupid , retarded , and fat ... Although the last one is truly my fault, LOL...I would like to learn all there is about this Var, and Fvar, and cos, and sin, and ifelse, and all the weird stuff in mugen, that I could read it and understand exactly what they mean, cuz I really don't understand siht...When I read all this, I feel like you guys are doing to me what that girl in eddy515's avatar is doing to the guy...
greetlock said, October 17, 2007, 09:08:08 pmI would like to learn all there is about this Var, and Fvar, and cos, and sin, and ifelse, and all the weird stuff in mugen, that I could read it and understand exactly what they mean, cuz I really don't understand siht...When I read all this, I feel like you guys are doing to me what that girl in eddy515's avatar is doing to the guy... Be patient and learn. I was almost like you a year ago