Pro tip: Ignore anything said by that idiot or his brother.
360 degree movement is a case of some fairly simple trig. I recommend just doing a search for articles here on 360 stuff. You don't really need to understand it to use it, though it helps.
Before we talk about shooting things, I'm going to tell you how to make one object smoothly rotate around another (like a moon orbiting a planet). They seem like very different ideas, but they work on the same principle. If you understand spinning around an object, you'll find shooting in 360 degrees much simpler
So imagine we want one object to rotate around another. Maybe we've got a planet, and we want a moon that spins round it. We need three objects for this:
The Earth (just an active object)
The Moon (another active object)
and a Counter (to tell us the angle of the moon in degrees. We'll call this object 'Angle')
If we keep adding 1 to the counter, it will make the moon spin around the earth.
We use two functions to do this.
sin() and cos()
Sin() gives you the Y POSITION of the moon, and
Cos() gives you the X POSITION of the moon.
What you do is you put an angle inside of sin() and cos(). So you might have sin(45) if the moon is at 45 degrees. Sin(90) if it's at 90 degrees. And so on. The same for Cos().
Since we're using a counter to hold the angle, we'll use sin(value("angle")) and cos(value("angle")).
Next we want to tell MMF how far away the moon is. We do this just by MULTIPLYING the sin() and cos() by the distance. So if we want an object to be 100px away, at a 45 degree angle, we would do this:
X position: cos(45)*100
Y position: sin(45)*100
That will put the moon at a 45 degree angle, 100px away.
However we just need to add one more thing. The position of the earth. As it is, it will rotate around the top left corner of the screen. This just tells it where the earth is so it spins around that instead. So the final code is:
X position: X("Earth") + ( cos(value("angle"))*100 )
Y position: Y("Earth") + ( sin(value("angle"))*100 )
Do you see how this works?
We start with the X and Y position of the Earth. Then we use the sin and cos functions to move the moon out and around the earth.
Shooting
Shooting is almost exactly the same. You know we had that counter to keep changing the angle, so the object spins? Well this time we're going to change the DISTANCE instead.
So we're gonna have an active object and call it 'bullet'. And we're going to give it some alterable values instead of counters.
You can right-click the object and change the names of the alterable values, so we'll change them to:
"Angle" (this will be the angle you shot the bullet at)
"Distance" (this will be how far it has travelled. We'll keep adding 1 to this)
"X start" (position the bullet was created at)
"Y start" (position the bullet was created at)
So we'll set the X and Y position of the bullet to:
X start("bullet") + ( cos(Angle("bullet")) * Distance("bullet") )
Y start("bullet") + ( sin(Angle("bullet")) * Distance("bullet") )
That's it. To break down what this is doing, read on:
It puts the bullet where it started.
Then it sets the angle and moves it away.
Because we keep adding to the distance, the bullet will appear further away each time.
Then you just do the 'on colision' stuff as with a normal bullet to destroy it and damage your enemies
I hope this wasn't too complicated. Just think of sin() and cos() as Y and X coordinates.
If you have any further questions, or need me to explain my explanation, just ask
To get the angle between two objects (in this case the angle between the player and the aimer), it's simplest to use the Advanced Direction Object (ADO).
You can use an expression from that object in the expression editor by right clicking the ADO and selecting:
Distance and Direction between two points
->Long Values (no decimals)
-->Direction Between Two Points (x1, y1, x2, y2)
This will give you an expression like this:
LongDir( "Advanced Direction Object", > Enter value here <, > Enter value here <,
> Enter value here <, > Enter value here < )
The first two values you give it are the X and Y of the player. The second two values are the X and Y of the aimer. So if the aimer follows the mouse you might do this::
LongDir( "Advanced Direction Object", X("player"), Y("player"),
xmouse, ymouse )
That'll give you the angle. You can then put the angle as an alterable value into the bullet.
Fastloops
You don't need to use these. All they do is make your bullets hit their target instantly. In most games it's nicer to actually see the bullet, which doesn't happen with fastloop.
"You don't need to use these. All they do is make your bullets hit their target instantly. In most games it's nicer to actually see the bullet, which doesn't happen with fastloop."
If you just always start the loop 5 times you can see them. Then on the loop you do X + cos(angle) and Y + sin(angle)
I think it is necessary, or else the bullets could pass straight through an enemy.
Ok, I got it working using the angle calculator rather than the ADO. I know now, It calculates the angle between the mouse and the shooting object, creates a bullet at the gun, and moves it at that angle. So simple once you get it. Everything is working fine now.