fix infinite range hook bug
This commit is contained in:
		
							parent
							
								
									a230d3ed06
								
							
						
					
					
						commit
						9ada88f4f5
					
				@ -34,10 +34,7 @@ function Player:new(x,y)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	-- hook values
 | 
						-- hook values
 | 
				
			||||||
	o.hook_swing_speed = math.rad(0.05)
 | 
						o.hook_swing_speed = math.rad(0.05)
 | 
				
			||||||
	o.hook_anchor = {
 | 
						o.hook_anchor = nil
 | 
				
			||||||
		x = nil,
 | 
					 | 
				
			||||||
		y = nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	-- walljump values
 | 
						-- walljump values
 | 
				
			||||||
	o.walljump_nodrift_amount = 12
 | 
						o.walljump_nodrift_amount = 12
 | 
				
			||||||
@ -166,7 +163,7 @@ function Player:doLogic()
 | 
				
			|||||||
		if self.is_hooked then
 | 
							if self.is_hooked then
 | 
				
			||||||
			self:unhook()
 | 
								self:unhook()
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			local anchor = self:checkNearest("HookAnchor",self.hook_distance)
 | 
								local anchor = self:checkNearest("HookAnchor","hook_specific")
 | 
				
			||||||
			if anchor then
 | 
								if anchor then
 | 
				
			||||||
				self.is_hooked = true
 | 
									self.is_hooked = true
 | 
				
			||||||
				self.hook_distance = anchor.hook_distance
 | 
									self.hook_distance = anchor.hook_distance
 | 
				
			||||||
@ -359,6 +356,7 @@ end
 | 
				
			|||||||
function Player:unhook()
 | 
					function Player:unhook()
 | 
				
			||||||
	self.is_hooked = false
 | 
						self.is_hooked = false
 | 
				
			||||||
	self.hook_anchor = nil
 | 
						self.hook_anchor = nil
 | 
				
			||||||
 | 
						self.hook_distance = nil
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function Player:debug()
 | 
					function Player:debug()
 | 
				
			||||||
 | 
				
			|||||||
@ -44,6 +44,8 @@ function Entity:checkNearest(type,maxdistance)
 | 
				
			|||||||
			local distance_y = entity.pos.y - self.pos.y
 | 
								local distance_y = entity.pos.y - self.pos.y
 | 
				
			||||||
			local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
 | 
								local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if maxdistance == "hook_specific" then maxdistance = entity.hook_distance end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if not maxdistance or distance < maxdistance then
 | 
								if not maxdistance or distance < maxdistance then
 | 
				
			||||||
				if shortest == -1 or distance < shortest then
 | 
									if shortest == -1 or distance < shortest then
 | 
				
			||||||
					shortest = distance
 | 
										shortest = distance
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user