- Fix wrond hedgehog speed calculation when using rope and changing rope length
authorunc0rr
Tue, 23 Dec 2008 20:44:32 +0000
changeset 1548 682c0c968997
parent 1547 4251f9598d54
child 1549 9cfb16a15e33
- Fix wrond hedgehog speed calculation when using rope and changing rope length - Should fix weird rope behaviour when touching land and changing rope length
hedgewars/GSHandlers.inc
--- a/hedgewars/GSHandlers.inc	Sun Dec 21 18:26:28 2008 +0000
+++ b/hedgewars/GSHandlers.inc	Tue Dec 23 20:44:32 2008 +0000
@@ -684,7 +684,7 @@
 					begin
 					X:= Gear^.X;
 					Y:= Gear^.Y;
-					if RopePoints.Count = 0 then RopePoints.HookAngle:= DxDy2Angle(Gear^.dY, Gear^.dX);
+					if RopePoints.Count = 0 then RopePoints.HookAngle:= DxDy2Angle(ropeDx, ropeDy);
 					b:= (cc * HHGear^.dY) > (cs * HHGear^.dX);
 					dLen:= len
 					end;
@@ -713,32 +713,29 @@
 			end
 		end;
 
-Gear^.dX:= HHGear^.X - Gear^.X;
-Gear^.dY:= HHGear^.Y - Gear^.Y;
+ropeDx:= HHGear^.X - Gear^.X;
+ropeDy:= HHGear^.Y - Gear^.Y;
 
-cs:= Gear^.dY + HHGear^.dY;
-cc:= Gear^.dX + HHGear^.dX;
+cs:= ropeDy + HHGear^.dY;
+cc:= ropeDx + HHGear^.dX;
 len:= _1 / Distance(cc, cs);
 cc:= cc * len;
 cs:= cs * len;
 
-HHGear^.dX:= HHGear^.X;
-HHGear^.dY:= HHGear^.Y;
+HHGear^.dX:= Gear^.X + cc*Gear^.Elasticity - HHGear^.X;
+HHGear^.dY:= Gear^.Y + cs*Gear^.Elasticity - HHGear^.Y;
 
 if ((Gear^.Message and gm_Down) <> 0) and (Gear^.Elasticity < Gear^.Friction) then
-	if not (TestCollisionXwithGear(HHGear, hwSign(Gear^.dX))
-			or TestCollisionYwithGear(HHGear, hwSign(Gear^.dY))) then Gear^.Elasticity:= Gear^.Elasticity + _0_3;
+	if not (TestCollisionXwithGear(HHGear, hwSign(ropeDx))
+			or TestCollisionYwithGear(HHGear, hwSign(ropeDy))) then Gear^.Elasticity:= Gear^.Elasticity + _0_3;
 
 if ((Gear^.Message and gm_Up) <> 0) and (Gear^.Elasticity > _30) then
-	if not (TestCollisionXwithGear(HHGear, -hwSign(Gear^.dX))
-			or TestCollisionYwithGear(HHGear, -hwSign(Gear^.dY))) then Gear^.Elasticity:= Gear^.Elasticity - _0_3;
+	if not (TestCollisionXwithGear(HHGear, -hwSign(ropeDx))
+			or TestCollisionYwithGear(HHGear, -hwSign(ropeDy))) then Gear^.Elasticity:= Gear^.Elasticity - _0_3;
 
 HHGear^.X:= Gear^.X + cc*Gear^.Elasticity;
 HHGear^.Y:= Gear^.Y + cs*Gear^.Elasticity;
 
-HHGear^.dX:= HHGear^.X - HHGear^.dX;
-HHGear^.dY:= HHGear^.Y - HHGear^.dY;
-
 if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then
 	HHGear^.dX:= -_0_6 * HHGear^.dX;
 if TestCollisionYwithGear(HHGear, hwSign(HHGear^.dY)) then