The Daily Click ::. Forums ::. Klik Coding Help ::. 360 shooting.
 

Post Reply  Post Oekaki 
 

Posted By Message

Greasy



Registered
  15/02/2005
Points
  322
19th September, 2005 at 22:55:27 -

Can anyone tell me how to do 360 shooting, so you cant shoot in just 32 directions.

 
n/a

Deleted User
19th September, 2005 at 23:04:31 -

yeh get the direction object it can do that

 

Greasy



Registered
  15/02/2005
Points
  322
21st September, 2005 at 19:59:42 -

I know, but I dont know how to use it, when I choose shoot an object in direction... the use calculation button is blanked out.

 
n/a

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
21st September, 2005 at 21:43:35 -

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.

 
n/a

Greasy



Registered
  15/02/2005
Points
  322
21st September, 2005 at 21:57:14 -

I want to be able to understand it, so I can modify it. I got destroyers 360 shooting thing, but it doesnt explain anything to me.

 
n/a

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
22nd September, 2005 at 08:27:15 -

Right, here's how it works.

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

Image Edited by the Author.

 
191 / 9999 * 7 + 191 * 7

Greasy



Registered
  15/02/2005
Points
  322
22nd September, 2005 at 19:39:17 -

Yeah, I finally get it, thank you., I might have more questions in a sec

 
n/a

Greasy



Registered
  15/02/2005
Points
  322
22nd September, 2005 at 19:48:20 -

I should use a fast loop right?

 
n/a

Greasy



Registered
  15/02/2005
Points
  322
22nd September, 2005 at 20:12:28 -

My bullets are floating along the top of the level when I press the mouse button.

 
n/a

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
22nd September, 2005 at 20:12:55 -

It's not necessary but it makes your bullets move faster if you need instant ones.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

Greasy



Registered
  15/02/2005
Points
  322
22nd September, 2005 at 20:28:03 -

Im trying to make it shoot towards an aimer , I might be able to figure this out by myself but probably not.

 
n/a

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
23rd September, 2005 at 07:51:37 -

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.

Image Edited by the Author.

 
191 / 9999 * 7 + 191 * 7

Destroyer (CrobaSoft)



Registered
  10/10/2004
Points
  1106
23rd September, 2005 at 07:55:35 -

"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.

 
Visit www.crobasoft.com or you're a Noob.

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
23rd September, 2005 at 08:12:05 -

Good point, I forgot about that.

 
191 / 9999 * 7 + 191 * 7

Greasy



Registered
  15/02/2005
Points
  322
23rd September, 2005 at 19:06:38 -

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.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click