So, I'd like to know how to code the classic asteroids movement in MMF2.
I've scavenged around the forum in search of it, but I can't seem to get it right.
The best example I found was this:
"At start of frame you set Alt. value a and Alt. value b of the spaceship to 0.0 so you can add floats to it.
When right is hold you add one to the direction of the spaceship, when left is hold you substract one.
Then you always set the x of the space ship to the x of the spaceship + alt. value a, and the y of the space ship to the y of the spaceship + alt. value b.
When up is hold you add the sin(direction of spaceship * 11.25) to alt. value a and add cos(direction of spaceship * 11.25) to alt. value b"
So I tried it out, but it didn't work. I've tweaked it and changed it but I can't get above code to work. So if someone feels smart, by all means.
Always
---Ship: Set Xvelocity to Xvelocity("Ship")+Cos(Angle("Ship"))*Acceleration("Ship")
---Ship: Set Yvelocity to Yvelocity("Ship")+Sin(Angle("Ship"))*Acceleration("Ship")
---Ship: Set Xposition to Xposition("Ship")+ Xvelocity("Ship") / [arbitrary value]
---Ship: Set Yposition to Yposition("Ship")+ Yvelocity("Ship") / [arbitrary value]
---Ship: Set X("Ship") to Xposition("Ship")
---Ship: Set Y("Ship") to Yposition("Ship")
Where
Xposition/Yposition are alt values used to store decimal positions
Xvelocity/Yvelocity are alt values that contain the x/y velocity
Angle is the current angle of the ship in 360 degrees (you might need to change the Yvelocity line to [Yvelocity("Ship")+Sin(Angle("Ship")-180)*Acceleration("Ship")] if you're using either MMF2's built-in angle value, or basing it on 32-directions, because directions in MMF are backwards for some reason)
Acceleration is an alt value set to some number when the thrust key is held, and set to zero when not held, and maybe a negative value if you want reverse thrust
Thanks both of you!
Though sadly, I can't check out Axel's example since I cant get the AlphaChannel.mfx. To get it you need to install the extpack-something which requires that you have the full-version of MMF2, and I haven't saved up the money yet. So I'll try Radix instructions! Unless anyone could send the AlphaChannel.mfx...?
Axel's example is pretty much what I posted in an Always event, and then like a dozen other events that do nothing but support the alpha channel object, so don't worry about it. If you're using MMF2 you can just use the built-in angle value actives have now, which makes this really simple.
Yeah, do that. I used Alpha Channel object purely for MMF 1.5 compatibility, but it's actually much easier to do with the built in AO rotation support. Just copy the code Radix posted and you should be fine.
Hmpf.
This is trickier than one would think. First I tried Radix code, as it was the ship just vanished in the blink of a loop. So I tweaked around a bit and almost got it to work, but it's something strange with it. Here's the code as it is now:
Always
---Ship: Set Xvelocity to Cos(Angle("Ship))*Acceleration("Ship")
---Ship: Set Yvelocity to Sin(Angle("Ship")-90)*Acceleration("Ship")
---Ship: Set Xposition("Ship")+Xvelocity("Ship")/10
---Ship: Set Yposition("Ship")+Yvelocity("Ship")/10
---Ship: Set X position to X("Ship")+Xposition("Ship")
---Ship: Set Y position to Y("Ship")+Yposition("Ship")
Repeat while "Up Arrow" is pressed
---Ship: Set Acceleration to 2
XRepeat while "Up Arrow" is pressed
---Ship: Set Acceleration to 0
Always
---Ship: Set Xvelocity to Xvelocity("Ship")+Cos(Angle("Ship"))*Acceleration("Ship")
---Ship: Set Yvelocity to Yvelocity("Ship")+Sin(Angle("Ship"))*Acceleration("Ship")
---Ship: Set Xposition to Xposition("Ship")+ Xvelocity("Ship") / [arbitrary value]
---Ship: Set Yposition to Yposition("Ship")+ Yvelocity("Ship") / [arbitrary value]
---Ship: Set X("Ship") to Xposition("Ship")
---Ship: Set Y("Ship") to Yposition("Ship")
I'd use an "arbitrary value" of like one or two hundred.
...
ok
...
*E_E feels kinda stupid*
...
*E_E get's an idea and does what every other non-english-as-first-language-ers does!*
But hey, english is not my first language.
Thanks for the pointer Radix!
Eternal Entertainment's Code'n'Art Man
E_E = All Indie
...actually Ell Endie, but whatever.
DaVince This fool just HAD to have a custom rating
Yeah, an accident in my childhood.
Anyways, I tried you're code again Radix but it still didn't work. So I switched the Cos and Sin so that you use Sin for Xvelocity and Cos for Yvelocity, voilá! It started to work, then by fiddling around with acceleration and the arbitrary value I got it to behave really nice. One thing you want though is to add an event that stops the X and Y position values at topspeed.
Thanks for all the help!
Once again!
A question!
Could you guys give me few pointers on how to convert the asteroids movement to a racecar movement? Like the built-in one. I'm doing an experiment... E_E
Always
---Ship: Set xpos to xpos("Ship") + Sin(Angle("Ship")) * Velocity("Ship")/100.0
---Ship: Set ypos to ypos("Ship") + Cos(Angle("Ship")) * Velocity("Ship")/100.0
---Ship: Set X position to xpos("Ship")
---Ship: Set Y position to ypos("Ship")
Where xpos/ypos are position holding alt values, and Velocity is the speed setting, which ranges from zero to whatever and is increased when up is held, and decreased when down is held.
Edit: Sorry, I just woke up and I misread your post. I thought you wanted a 360 degree racecar movement.
I'm not sure what you're asking now. If you want to be able to change the movement of your ship at runtime, just use the above code and convert the relevant values. If you just mean you want to use default racecar movement instead, there's not really any way to make the inertia work without using the same code anyway.
No, you got me right! I mean't a 360 degree one! I can't tell you how grateful I am for all the help. I hope this works out, if it does, I'll be sure to cred you bigtime!
Thanks from E_E!