Scene Changes and bug fixes #431
|
@ -37,9 +37,15 @@ public class PickAndThrow : Script
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
private TweenThread camArmTween;
|
private TweenThread camArmTween;
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
private TweenThread foodTween;
|
private TweenThreadVec3 offSetCamTween;
|
||||||
|
[NonSerialized]
|
||||||
|
private TweenThreadVec3 foodTween;
|
||||||
|
|
||||||
public float tweenDuration = 0.3f;
|
public float tweenPickUpDuration = 0.5f;
|
||||||
|
public float tweenAimDuration = 0.3f;
|
||||||
|
private bool createFoodTween = true;
|
||||||
|
private bool createCamTween = true;
|
||||||
|
private bool camTweenUpdate = false;
|
||||||
|
|
||||||
protected override void awake()
|
protected override void awake()
|
||||||
{
|
{
|
||||||
|
@ -76,21 +82,32 @@ public class PickAndThrow : Script
|
||||||
CalculateDir();
|
CalculateDir();
|
||||||
CastRay();
|
CastRay();
|
||||||
|
|
||||||
|
if (camTweenUpdate)
|
||||||
|
{
|
||||||
|
pc.camArm.TargetOffset = offSetCamTween.GetValue();
|
||||||
|
pc.camArm.ArmLength = camArmTween.GetValue();
|
||||||
|
|
||||||
|
if (offSetCamTween.IsCompleted() && camArmTween.IsCompleted())
|
||||||
|
camTweenUpdate = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (pc && itemRidigBody && itemTransform && itemCollider)
|
if (pc && itemRidigBody && itemTransform && itemCollider)
|
||||||
{
|
{
|
||||||
if (pc.holdItem)
|
if (pc.holdItem)
|
||||||
{
|
{
|
||||||
itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition;
|
TweenFood();
|
||||||
itemTransform.LocalRotation = pc.tranform.LocalRotation;
|
itemTransform.LocalRotation = pc.tranform.LocalRotation;
|
||||||
|
itemRidigBody.ClearForces();
|
||||||
|
itemRidigBody.ClearTorque();
|
||||||
itemRidigBody.LinearVelocity = Vector3.Zero;
|
itemRidigBody.LinearVelocity = Vector3.Zero;
|
||||||
itemRidigBody.AngularVelocity = Vector3.Zero;
|
itemRidigBody.AngularVelocity = Vector3.Zero;
|
||||||
|
|
||||||
if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton))
|
if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton))
|
||||||
{
|
{
|
||||||
pc.isAiming = true;
|
pc.isAiming = true;
|
||||||
pc.camArm.ArmLength = aimingLength;
|
TweenAimCamArm();
|
||||||
prevTargetOffSet = pc.camArm.TargetOffset;
|
//pc.camArm.TargetOffset = cameraArmOffSet;
|
||||||
pc.camArm.TargetOffset = cameraArmOffSet;
|
//pc.camArm.ArmLength = aimingLength;
|
||||||
pc.cam.FOV = Settings.cameraFOV + 5;
|
pc.cam.FOV = Settings.cameraFOV + 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,11 +117,12 @@ public class PickAndThrow : Script
|
||||||
itemRidigBody.IsGravityEnabled = true;
|
itemRidigBody.IsGravityEnabled = true;
|
||||||
itemCollider.GetCollisionShape(0).IsTrigger = false;
|
itemCollider.GetCollisionShape(0).IsTrigger = false;
|
||||||
pc.isAiming = false;
|
pc.isAiming = false;
|
||||||
|
createCamTween = true;
|
||||||
pc.camArm.TargetOffset = prevTargetOffSet;
|
pc.camArm.TargetOffset = prevTargetOffSet;
|
||||||
pc.cam.FOV = Settings.cameraFOV;
|
|
||||||
if (tpc)
|
|
||||||
pc.camArm.ArmLength = tpc.armLength;
|
pc.camArm.ArmLength = tpc.armLength;
|
||||||
|
pc.cam.FOV = Settings.cameraFOV;
|
||||||
pc.holdItem = false;
|
pc.holdItem = false;
|
||||||
|
createFoodTween = true;
|
||||||
inRange = false;
|
inRange = false;
|
||||||
throwItem = true;
|
throwItem = true;
|
||||||
PlayThrowAnimation();
|
PlayThrowAnimation();
|
||||||
|
@ -114,6 +132,7 @@ public class PickAndThrow : Script
|
||||||
if (Input.GetMouseButtonDown(Input.MouseCode.RightButton) && !pc.isAiming)
|
if (Input.GetMouseButtonDown(Input.MouseCode.RightButton) && !pc.isAiming)
|
||||||
{
|
{
|
||||||
pc.holdItem = false;
|
pc.holdItem = false;
|
||||||
|
createFoodTween = true;
|
||||||
inRange = false;
|
inRange = false;
|
||||||
itemRidigBody.IsGravityEnabled = true;
|
itemRidigBody.IsGravityEnabled = true;
|
||||||
itemCollider.GetCollisionShape(0).IsTrigger = false;
|
itemCollider.GetCollisionShape(0).IsTrigger = false;
|
||||||
|
@ -124,8 +143,9 @@ public class PickAndThrow : Script
|
||||||
{
|
{
|
||||||
pc.isAiming = false;
|
pc.isAiming = false;
|
||||||
pc.cam.FOV = Settings.cameraFOV;
|
pc.cam.FOV = Settings.cameraFOV;
|
||||||
|
createCamTween = true;
|
||||||
|
//TweenAimCamArm(false);
|
||||||
pc.camArm.TargetOffset = prevTargetOffSet;
|
pc.camArm.TargetOffset = prevTargetOffSet;
|
||||||
if (tpc)
|
|
||||||
pc.camArm.ArmLength = tpc.armLength;
|
pc.camArm.ArmLength = tpc.armLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,9 +257,11 @@ public class PickAndThrow : Script
|
||||||
Vector3 playerRayPos = pc.tranform.GlobalPosition;
|
Vector3 playerRayPos = pc.tranform.GlobalPosition;
|
||||||
playerRayPos.y += rayHeight;
|
playerRayPos.y += rayHeight;
|
||||||
dirNor.Normalise();
|
dirNor.Normalise();
|
||||||
List<RaycastHit> rayList1 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(22.5f))), rayDistance, false, (ushort)65535);
|
List<RaycastHit> rayList1 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(25.0f))), rayDistance, false, (ushort)65535);
|
||||||
List<RaycastHit> rayList2 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(-22.5f))), rayDistance, false, (ushort)65535);
|
List<RaycastHit> rayList2 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(-25.0f))), rayDistance, false, (ushort)65535);
|
||||||
List<RaycastHit> rayList3 = Physics.Raycast(new Ray(playerRayPos, dirNor), rayDistance * 0.75f, false, (ushort)65535);
|
List<RaycastHit> rayList3 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(12.5f))), rayDistance, false, (ushort)65535);
|
||||||
|
List<RaycastHit> rayList4 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(-12.5f))), rayDistance, false, (ushort)65535);
|
||||||
|
List<RaycastHit> rayList5 = Physics.Raycast(new Ray(playerRayPos, dirNor), rayDistance , false, (ushort)65535);
|
||||||
|
|
||||||
if (rayList1.Count > 0)
|
if (rayList1.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -259,6 +281,18 @@ public class PickAndThrow : Script
|
||||||
inRange = CheckForItem(ray3);
|
inRange = CheckForItem(ray3);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (rayList4.Count > 0)
|
||||||
|
{
|
||||||
|
RaycastHit ray4 = rayList4[0];
|
||||||
|
inRange = CheckForItem(ray4);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (rayList5.Count > 0)
|
||||||
|
{
|
||||||
|
RaycastHit ray5 = rayList5[0];
|
||||||
|
inRange = CheckForItem(ray5);
|
||||||
|
return;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
inRange = false;
|
inRange = false;
|
||||||
|
@ -394,4 +428,31 @@ public class PickAndThrow : Script
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void TweenFood()
|
||||||
|
{
|
||||||
|
if (createFoodTween)
|
||||||
|
{
|
||||||
|
foodTween = TweenManager.CreateTweenThreadVec3(tweenPickUpDuration, itemTransform.LocalPosition, raccoonHoldLocation.GlobalPosition, EASING_METHOD.EASE_IN_SINE);
|
||||||
|
createFoodTween = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemTransform.LocalPosition = foodTween.GetValue();
|
||||||
|
|
||||||
|
if (foodTween.IsCompleted())
|
||||||
|
itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TweenAimCamArm()
|
||||||
|
{
|
||||||
|
if (createCamTween)
|
||||||
|
{
|
||||||
|
offSetCamTween = TweenManager.CreateTweenThreadVec3(tweenAimDuration, pc.camArm.TargetOffset, cameraArmOffSet, EASING_METHOD.EASE_IN_SINE);
|
||||||
|
camArmTween = TweenManager.CreateTweenThread(tweenPickUpDuration, pc.camArm.ArmLength, aimingLength, EASING_METHOD.EASE_IN_SINE);
|
||||||
|
camTweenUpdate = true;
|
||||||
|
Debug.Log($"camera arm lenght: {pc.camArm.ArmLength} aimingLength:{aimingLength} ");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -181,10 +181,15 @@ public class PlayerController : Script
|
||||||
{
|
{
|
||||||
cam = GetComponentInChildren<Camera>();
|
cam = GetComponentInChildren<Camera>();
|
||||||
if (pat)
|
if (pat)
|
||||||
|
{
|
||||||
cam.FOV = Settings.cameraFOV;
|
cam.FOV = Settings.cameraFOV;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!camArm)
|
if (!camArm)
|
||||||
|
{
|
||||||
camArm = GetComponentInChildren<CameraArm>();
|
camArm = GetComponentInChildren<CameraArm>();
|
||||||
|
pat.prevTargetOffSet = camArm.TargetOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue