From 736de25e6c324c05419d107af6759a422ecdd524 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Sun, 27 Aug 2017 18:45:14 +0300 Subject: [PATCH] Fixed RangedWeapon launching projectiles in an incorrect rotation --- .../Source/Items/Components/Holdable/RangedWeapon.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs index b7885799f..68de9ee7b 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs @@ -89,17 +89,20 @@ namespace Barotrauma.Items.Components //so that the player can't shoot himself Projectile projectileComponent= projectile.GetComponent(); if (projectileComponent == null) continue; + + float rotation = ((item.body.Dir == 1.0f) ? item.body.Rotation : item.body.Rotation - MathHelper.Pi) + Rand.Range(-degreeOfFailure, degreeOfFailure); projectile.body.ResetDynamics(); - projectile.SetTransform(TransformedBarrelPos, - ((item.body.Dir == 1.0f) ? item.body.Rotation : item.body.Rotation - MathHelper.Pi) - + Rand.Range(-degreeOfFailure, degreeOfFailure)); + projectile.SetTransform(TransformedBarrelPos, rotation); projectile.Use(deltaTime); projectileComponent.User = character; projectile.body.ApplyTorque(projectile.body.Mass * degreeOfFailure * Rand.Range(-10.0f, 10.0f)); + //set the rotation of the projectile again because dropping the projectile resets the rotation + projectile.SetTransform(projectile.SimPosition, rotation); + //recoil item.body.ApplyLinearImpulse( new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * item.body.Mass * -50.0f);