Be a Supporter!

Bullet At Orgin Of Rotating Gun As2

  • 422 Views
  • 5 Replies
New Topic Respond to this Topic
glitchs2d
glitchs2d
  • Member since: Oct. 22, 2010
  • Offline.
Forum Stats
Member
Level 08
Melancholy
Bullet At Orgin Of Rotating Gun As2 2011-01-03 15:31:47 Reply

I have the gun rotating towards the mouse I just need the bullets to rotate around the barrel of the gun. If you dont understand what Im asking here is what I have so far. http://www.newgrounds.com/dump/item/f28c 7b9919b2768402a3092cccb5d41c

Tygerman
Tygerman
  • Member since: Aug. 16, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Bullet At Orgin Of Rotating Gun As2 2011-01-03 15:34:34 Reply

the bullets' origin co-ordinates need to be at the bulk of the gun instead of the dog's center


BBS Signature
glitchs2d
glitchs2d
  • Member since: Oct. 22, 2010
  • Offline.
Forum Stats
Member
Level 08
Melancholy
Response to Bullet At Orgin Of Rotating Gun As2 2011-01-03 15:45:07 Reply

I tried that but it dosent rotate around the barrel of the gun I put down

function playerShooting()
	{



		if (_root.dog.time > 6 && _root.dog.ammo > 0)
		{
			var bullet = _root.attachMovie("Bullet", "Bullet" + _root.getNextHighestDepth(), _root.getNextHighestDepth());
			bullet._x = this.xOrgin + 100 ;
			bullet._y = this.yOrgin;
			bullet.xSpeed = Math.cos(radians) * bulletSpeed;
			bullet.ySpeed = Math.sin(radians) * bulletSpeed;
			bullet.bulletSpeed = 30;
			bullet._rotation = degrees;
			trace(bullet._x);
			trace(bullet._y);
			

			
			_root.dog.ammo -= 1;
			_root.dog.time = 0;
			_root.dog.updateAmmo();


		}
tomdeaap
tomdeaap
  • Member since: Mar. 27, 2009
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to Bullet At Orgin Of Rotating Gun As2 2011-01-03 15:59:58 Reply

Easy solution:
On the movieclip of the gun add a small block where you want the bullets to spawn from. Call this bulletblock, or whatever you want. Now just turn the opacity of it down ( or put it under your gun, just hide it OK? ) and add the bullets at the x and y positions of the block. Be sure to add the global position to it ( that of the gun, or the dog or both dunno how you've set it up ) or use the localtoglobal to acquire the correct point ( google that shit up ).

Good luck :3


"Insert deep, brain twisting sentence here"

glitchs2d
glitchs2d
  • Member since: Oct. 22, 2010
  • Offline.
Forum Stats
Member
Level 08
Melancholy
Response to Bullet At Orgin Of Rotating Gun As2 2011-01-04 00:03:05 Reply

Ive tried multiple ways and looked at examples I just done know how to get globalToLocal to work. Here is the code im working with.

class FrontOfArms extends MovieClip
{

	var D;
	var Dx;
	var Dy;
	var xOrgin;
	var yOrgin;
	var radians;
	var line;
	var degrees;
	var bulletSpeed;
	
	function onLoad()
	{
		bulletSpeed = 30;
				
		
	}
	
	

	function onEnterFrame()
	{
		 
		
			  
		
		this._x += _root.dog.walkSpeed;
		
		if (this._xscale == 100 && _root._xmouse > this._x || this._xscale == -100 && _root._xmouse > this._x)
		{

			this._xscale = 100;
			this._yscale = 100;
			this._x = _root.dog._x - 10;
		}

		if (this._xscale == 100 && _root._xmouse < this._x || this._xscale == -100 && _root._xmouse > this._x)
		{

			this._yscale = -100;
			this._x = _root.dog._x + 10;
		}
		
		
		xOrgin = this._x ;
		yOrgin = this._y + 40;

		Dx = _root._xmouse - xOrgin;
		Dy = _root._ymouse - yOrgin;
		radians = Math.atan2(Dy, Dx);
		degrees = (360 * radians)/ ( 2 * Math.PI);
		this._rotation = degrees;
		
		


	}
	
	function playerShooting()
	{



		if (_root.dog.time > 6 && _root.dog.ammo > 0)
		{
			var bullet = _root.attachMovie("Bullet", "Bullet" + _root.getNextHighestDepth(), _root.getNextHighestDepth());
			bullet._x = _x;
			bullet._y = _y;
			bullet.xSpeed = Math.cos(radians) * bulletSpeed;
			bullet.ySpeed = Math.sin(radians) * bulletSpeed;
			bullet.bulletSpeed = 30;
			bullet._rotation = degrees;
			trace(bullet._x);
			trace(bullet._y);
			
			
			

			
			_root.dog.ammo -= 1;
			_root.dog.time = 0;
			_root.dog.updateAmmo();


		}


}}
glitchs2d
glitchs2d
  • Member since: Oct. 22, 2010
  • Offline.
Forum Stats
Member
Level 08
Melancholy
Response to Bullet At Orgin Of Rotating Gun As2 2011-01-04 18:02:18 Reply

Figured it out nevermind