AngleDraw code help

Started by ssjsongoku, January 01, 2008, 11:11:28 PM

Previous topic - Next topic

ssjsongoku

Basically, I have a sword (helper) that is supposed to stay inplace and rotate with angledraw so that the tip of the sword always points at p2.
I did it...for the most part, but when p2 jumps and is directly above the sword, the sword makes a vertical flip for a tick or so (small amount of time) and then return to the way if should be.

Heres what I have now:


[State 0, VarSet]
type = VarSet
trigger1 = 1;
v = 19
value = 90.0-180.0/pi*atan(p2dist Y/p2dist X)

[State 0, AngleDraw]
type = AngleDraw
trigger1 = time >= 0
value = ifelse(abs(p2dist X)<.1, ifelse(p2dist Y <= 0, 0.0, 180.0), ifelse( p2dist X>=0  ,var(19), 180.0+var(19)))


How can i fix the vertical flipping thing?


Byakko

Quote(p2dist Y/p2dist X)
When P2 is "directly above the sword", p2dist x = 0. You're dividing by zero. You should even have a debug message if you tried turning the debug mode on (ctrl + d).

Add a second version of your varset triggered when p2dist x = 0 and give it a particular value, then in the current varset, add the trigger p2dist x != 0.
If I struggled to the end of my determination, to the end of my way of life with my followers, if the result is ruin, then this ruin is inevitable. Grieve. Shed tears. But you cannot regret.

ssjsongoku

There isn't any devision by 0 because the first ifelse prevents it. o.o

Byakko

#3
First, regardless of your ifelse, there will be a division by 0.  What do you think happens when p2dist x = 0 and Mugen reads this ?
Quotevalue = 90.0-180.0/pi*atan(p2dist Y/p2dist X)

Then, about your ifelse. When p2dist X = 0, it reads "ifelse(p2dist Y <= 0, 0.0, 180.0)", which will be 0 when p2 is above you. So the angledraw is 0 when the opponent is right over your sword. How is your sprite oriented ?
If I struggled to the end of my determination, to the end of my way of life with my followers, if the result is ruin, then this ruin is inevitable. Grieve. Shed tears. But you cannot regret.

ssjsongoku

#4
But isn't it irrelevant, as var(19) is not used thanks to the ifelse that ignores it whenever abs(p2dist X)<.1 ?
(see the last line of the code)

::

The thing is, when the character is right below or above the sprite, then it doesn't know whether it should be pointing up or down.
Hence the ifelse(p2dist Y<=0, 0., 180.), to guess the orientation when p2dist X~0.

However, this code sometimes errs, and I have difficulty fixing it.

Byakko

You must have replied while I was editing my post above, check it again.
If I struggled to the end of my determination, to the end of my way of life with my followers, if the result is ruin, then this ruin is inevitable. Grieve. Shed tears. But you cannot regret.

ssjsongoku


Byakko

#7
Again, it depends on how you oriented your sprite.
Basically, when the opponent is right above the sword, it will read "angledraw value = 180.0 0.0" mixed up the two again. So if your original sprite has the sword pointing updownward, the angledraw will draw it pointing downward. Hence why I'm asking which way your sprite is oriented.
If I struggled to the end of my determination, to the end of my way of life with my followers, if the result is ruin, then this ruin is inevitable. Grieve. Shed tears. But you cannot regret.

Cyanide

value = 90+(atan((fvar(3))/(ifelse(facing = 1, var(2) - Pos X , pos X - Var(2))))*(-180/Pi))

Through lots of tweaking and swearing at code that apparently was meant to work but didn't this equation got me the effect you're after in g-mel's missiles in my SBME game.

var(2) = floor(enemy, pos X)
fvar(3) = p2dist Y

I forget why i did it that way but it works.


In M.U.G.E.N there is no magic button

They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance.

ssjsongoku

#9
When the angle is 0 then the sword is pointing downwards.
In other words, the original sprite has the sword pointing downwards.

:: Edit, to Cyanide:
Thank you for this code. I will try it out (and maybe even understand it :) ).

:: Edit to Baiken:
Your comment about the orientation was right on. It seems that it all boiled down to swapping 0 with 180
in the p2dist Y ifelse.

Thank you both for your help.