MobGunner = {againstWall = 0}
MobGunner.__index = MobGunner

function MobGunner.LoadAssets(me)
	LoadModel(me,"Wheel","Animated")
end

function MobGunner:Create(me)
	SetHealth(me,1)
	--SetHealth(me,20)	
	SetPower(me,1)
	--ChangeAnimation(me,"Stand")
	--self.Update = Instance.CustomUpdate
	--SetState(me,0)
	
	--playerDirection = GetPlayerDirection(me)
	
end

function MobGunner:Update(me)
	--TargetPlayer(me)
	if ( GetLifetime(me) == 0)
	then
		TargetPlayer(me)
		SetVelocity(me,10*GetDirection(me),0)
	end

	--Change direction if opposite player
	x,y = GetPosition(me)
	px,py = GetPosition(GetPlayer())
	if ( (x - px)*GetDirection(me) > 0 )
	then
		
		vx,vy = GetVelocity(me)
		if ( vx * GetDirection(me) > .5 )
		then
			SetVelocity(me, vx - .5*GetDirection(me), vy)
		elseif vx * GetDirection(me) == .5
		then
			SetVelocity(me, 0, vy)
			self.againstWall = 30
		end
		
		
	end


	
	--Returning from against the wall
	if(self.againstWall == 1)
	then
		SetDirection(me, GetDirection(me)*-1)
		SetVelocity(me,10*GetDirection(me),0)
	end
	if(self.againstWall > 0 )
	then
		self.againstWall = self.againstWall - 1
	
	--else if(math.abs(x) < 10 )
	--then
		--x,y = GetVelocity(me)
		--SetVelocity(me, x + .25*GetDirection(me),0)
	end
end

function MobGunner:Collide(me, you)
	SetHealth(me,0)

	Smash(you,10*GetDirection(me),-1)
end


function MobGunner:CollideWorld(me)
	ShakeScreen(8)
	TakeDamage(me, 2)
	SetVelocity(me,0,0)
	PlaySoundEffect(1)
end

function MobGunner:CollideWall(me)
	ShakeScreen(8)
	--TakeDamage(me, 2)
	--SetVelocity(me,0,0)
	PlaySoundEffect(1)
	self.againstWall = 20
	SetHealth(me,0)
end

function MobGunner:Death(me)
	x,y = GetPosition(me)
	y = y - 32
	CreateEmitter("Explosion", x,y)
end