The Daily Click ::. Forums ::. Klik Coding Help ::. 360 Degree Multiple Instances
 

Post Reply  Post Oekaki 
 

Posted By Message

vetmora120



Registered
  07/01/2010
Points
  273
7th August, 2010 at 15:49:25 -

So I'm trying to make turrets shoot 360 degrees at the same time, using multiple instances of the same object. I thought the best way to do this would be by spreading values and using fast loops, however I can not seem to get it to work. Any ideas? What's the proper way to achieve this? Anyone got an example or anything to share?

Thanks, Vetmora

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
7th August, 2010 at 17:19:50 -

You don't need spread values or fast loops.
You didn't say exactly what you're trying to achieve, so I'm going to assume that the turrets are all supposed to shoot at the player once every second, when they are within range.
Anything in italics is an alterable value.

// Aim turret.
+ Always
-> Turret: Set Angle to ATan2(Y("Turret")-Y("Player"), X("Player")-X("Turret"))
-> Turret: Set Range to Sqr(((X("Turret")-X("Player")) pow 2)+((Y("Turret")-Y("Player")) pow 2))

// Fire bullet.
+ Range("Turret") <= FiringRange("Turret")
+ Restrict actions for 1 second
-> Create Bullet at 0,0 from Turret

// Set bullet movement vector.
+ Flag 0 of Bullet is OFF
-> Bullet: Set XPos to X("Bullet")
-> Bullet: Set YPos to Y("Bullet")
-> Bullet: Set Angle to ATan2(Y("Bullet")-Y("Player"), X("Player")-X("Bullet"))
-> Bullet: Set XVel to Cos(Angle("Bullet"))*Velocity("Bullet")
-> Bullet: Set YVel to 0-Sin(Angle("Bullet"))*Velocity("Bullet")
-> Bullet: Set Flag 0 to ON

// Move bullet.
+ Always
-> Bullet: Set XPos to XPos("Bullet")+XVel("Bullet")
-> Bullet: Set YPos to YPos("Bullet")+YVel("Bullet")
-> Bullet: Set X position to XPos("Bullet")
-> Bullet: Set Y position to YPos("Bullet")

Edited by Sketchy

 
n/a

vetmora120



Registered
  07/01/2010
Points
  273
7th August, 2010 at 17:40:06 -

Hey Sketchy, thanks for the reply. I've just tried this and it doesn't seem to work. The turrets look at the player so nothing wrong there but they're not shooting any bullets... Don't think I entered anything wrongly.

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
7th August, 2010 at 18:00:12 -

Did you set the alterable values "FiringRange" and "Velocity"?
I just checked it, and it works fine:
http://cid-b1e7ee094271bbda.office.live.com/self.aspx/Public/360ShootDemo.mfa

 
n/a

vetmora120



Registered
  07/01/2010
Points
  273
7th August, 2010 at 18:08:53 -

Yep, don't worry I got it working now, thanks. One of the events was too high on the list Woops... Thanks heaps, I'd been searching for ages for one of these

 
n/a

vetmora120



Registered
  07/01/2010
Points
  273
7th August, 2010 at 18:27:28 -

Actually, when I inputted this into my game after I was sure it worked, something went weird. The turrets work fine until I move the player in-game then they stop. If I stay still for a few seconds they start again, and stop when I move. Any idea why this could be happening? I havn't changed the code at all.

Edited by vetmora120

 
n/a

vetmora120



Registered
  07/01/2010
Points
  273
7th August, 2010 at 18:45:21 -

Again, my own error. I had somewhere an event that was setting the global timer to 0 when left/right was pressed therefore resetting the restrict actions shoot. My bad

 
n/a

Jon C-B

I create vaporware

Registered
  23/04/2008
Points
  237

I'm an alien!VIP MemberWii OwnerI donated an open source project Santa Hat
7th August, 2010 at 18:50:50 -

Dang what dont you know how to do in MMF Sketchy?

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
7th August, 2010 at 18:55:11 -

Ah, okay. I was just going to say I had no clue what could be causing that

@Jon: Quite a lot. Like make an actual complete game for starters

Edited by Sketchy

 
n/a
   

Post Reply



 



Advertisement

Worth A Click