public void SetAimTarget(Vector3 targetPosition) { aimDir = (targetPosition - vObject.GetPosition()).normalized; if (axis == Axis.XZ) { unitSkeletonCompositeWeapon.SetAimTarget(new Vector3(aimDir.x, aimDir.z)); } else { unitSkeletonCompositeWeapon.SetAimTarget(aimDir); } }
public void SetAimTarget(Vector3 aimTargetPosition) { this.aimTargetPosition = aimTargetPosition; Vector3 aimDir = (aimTargetPosition - parentObject.GetPosition()).normalized; // Decide if should use Right or Left Body Part if (!isShooting) { switch (UnitAnim.GetAnimDirFromVector(aimDir)) { default: case UnitAnim.AnimDir.Down: case UnitAnim.AnimDir.DownRight: case UnitAnim.AnimDir.Right: case UnitAnim.AnimDir.UpRight: case UnitAnim.AnimDir.Up: if (!usingSkeletonRight) { // Switch sides usingSkeletonRight = true; activeAnimAimWeapon = animAimWeaponRight; activeAnimShootWeapon = animShootWeaponRight; unitSkeleton.ReplaceAllBodyPartsInAnimation(activeAnimAimWeapon); } break; case UnitAnim.AnimDir.UpLeft: case UnitAnim.AnimDir.Left: case UnitAnim.AnimDir.DownLeft: if (usingSkeletonRight) { // Switch sides usingSkeletonRight = false; activeAnimAimWeapon = animAimWeaponLeft; activeAnimShootWeapon = animShootWeaponLeft; unitSkeleton.ReplaceAllBodyPartsInAnimation(activeAnimAimWeapon); } break; } } // Show on top of Body for all except Up bool weaponOnTopOfBody = UnitAnim.GetAnimDirFromVectorLimit4Directions(aimDir) != UnitAnim.AnimDir.Up; int bonusOffset = 2000; if (usingSkeletonRight) { activeAnimAimWeapon.ApplyAimDir(aimDir, positionOffset, weaponOnTopOfBody ? +bonusOffset : -bonusOffset); activeAnimShootWeapon.ApplyAimDir(aimDir, positionOffset, weaponOnTopOfBody ? +bonusOffset : -bonusOffset); } else { activeAnimAimWeapon.ApplyAimDir(CodeMonkey.Utils.UtilsClass.ApplyRotationToVector(aimDir, 180), positionOffset, weaponOnTopOfBody ? +bonusOffset : -bonusOffset); activeAnimShootWeapon.ApplyAimDir(CodeMonkey.Utils.UtilsClass.ApplyRotationToVector(aimDir, 180), positionOffset, weaponOnTopOfBody ? +bonusOffset : -bonusOffset); } }
public void SetAimTarget(Vector3 targetPosition) { aimDir = (targetPosition - vObject.GetPosition()).normalized; if (isReloading) { unitSkeletonCompositeWeaponReload.SetAimTarget(targetPosition); } else { unitSkeletonCompositeWeapon.SetAimTarget(targetPosition); } }
public void SetAimTarget(Vector3 aimTargetPosition) { this.aimTargetPosition = aimTargetPosition; Vector3 aimDir = (aimTargetPosition - parentObject.GetPosition()).normalized; // Decide if should use Inverted Vertical Body Part if (!isShooting) { switch (UnitAnim.GetAnimDirFromVector(aimDir)) { default: case UnitAnim.AnimDir.Down: case UnitAnim.AnimDir.DownRight: case UnitAnim.AnimDir.Right: case UnitAnim.AnimDir.UpRight: case UnitAnim.AnimDir.Up: if (!usingSkeletonNormal) { // Switch sides usingSkeletonNormal = true; activeAnimAimWeaponRight = animAimWeaponRight; activeAnimShootWeaponRight = animShootWeaponRight; unitSkeleton.ReplaceAllBodyPartsInAnimation(activeAnimAimWeaponRight); } break; case UnitAnim.AnimDir.UpLeft: case UnitAnim.AnimDir.Left: case UnitAnim.AnimDir.DownLeft: if (usingSkeletonNormal) { // Switch sides usingSkeletonNormal = false; activeAnimAimWeaponRight = animAimWeaponRightInvertV; activeAnimShootWeaponRight = animShootWeaponRightInvertV; unitSkeleton.ReplaceAllBodyPartsInAnimation(activeAnimAimWeaponRight); } break; } } // Show on top of Body for all except Up bool weaponOnTopOfBody = UnitAnim.GetAnimDirFromVectorLimit4Directions(aimDir) != UnitAnim.AnimDir.Up; activeAnimAimWeaponRight.ApplyAimDir(aimDir, new Vector3(0, -2), weaponOnTopOfBody ? +1000 : -1000); activeAnimShootWeaponRight.ApplyAimDir(aimDir, new Vector3(0, -2), weaponOnTopOfBody ? +1000 : -1000); }
// Use this for initialization private void Start() { V_Object vObject = CreateBasicUnit(transform, new Vector3(500, 680), 30f, GameAssets.i.m_MarineSpriteSheet); V_UnitAnimation unitAnimation = vObject.GetLogic <V_UnitAnimation>(); V_UnitSkeleton unitSkeleton = vObject.GetLogic <V_UnitSkeleton>(); V_IObjectTransform objectTransform = vObject.GetLogic <V_IObjectTransform>(); bool canShoot = true; V_UnitSkeleton_Composite_Weapon unitSkeletonCompositeWeapon = new V_UnitSkeleton_Composite_Weapon(vObject, unitSkeleton, GameAssets.UnitAnimEnum.dMarine_AimWeaponRight, GameAssets.UnitAnimEnum.dMarine_AimWeaponRightInvertV, GameAssets.UnitAnimEnum.dMarine_ShootWeaponRight, GameAssets.UnitAnimEnum.dMarine_ShootWeaponRightInvertV); vObject.AddRelatedObject(unitSkeletonCompositeWeapon); unitSkeletonCompositeWeapon.SetActive(); V_UnitSkeleton_Composite_Walker unitSkeletonCompositeWalker_BodyHead = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "Body", "Head" }); vObject.AddRelatedObject(unitSkeletonCompositeWalker_BodyHead); V_UnitSkeleton_Composite_Walker unitSkeletonCompositeWalker_Feet = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "FootL", "FootR" }); vObject.AddRelatedObject(unitSkeletonCompositeWalker_Feet); // Update Code bool isAimDownSights = false; FunctionUpdater.Create(() => { Vector3 targetPosition = UtilsClass.GetMouseWorldPosition(); Vector3 aimDir = (targetPosition - vObject.GetPosition()).normalized; fieldOfView.transform.up = (aimDir); // Check for hits Vector3 gunEndPointPosition = vObject.GetLogic <V_UnitSkeleton>().GetBodyPartPosition("MuzzleFlash"); RaycastHit2D raycastHit = Physics2D.Raycast(gunEndPointPosition, (targetPosition - gunEndPointPosition).normalized, Vector3.Distance(gunEndPointPosition, targetPosition)); if (raycastHit.collider != null) { // Hit something targetPosition = raycastHit.point; } unitSkeletonCompositeWeapon.SetAimTarget(targetPosition); if (canShoot && Input.GetMouseButton(0)) { // Shoot canShoot = false; // Replace Body and Head with Attack unitSkeleton.ReplaceBodyPartSkeletonAnim(GameAssets.UnitAnimTypeEnum.dMarine_Attack.GetUnitAnim(aimDir), "Body", "Head"); // Shoot Composite Skeleton unitSkeletonCompositeWeapon.Shoot(targetPosition, () => { canShoot = true; }); // Add Effects Vector3 shootFlashPosition = vObject.GetLogic <V_UnitSkeleton>().GetBodyPartPosition("MuzzleFlash"); if (OnShoot != null) { OnShoot(this, new OnShootEventArgs { gunEndPointPosition = shootFlashPosition, shootPosition = targetPosition }); } //Shoot_Flash.AddFlash(shootFlashPosition); //WeaponTracer.Create(shootFlashPosition, targetPosition); } // Manual Movement bool isMoving = false; Vector3 moveDir = new Vector3(0, 0); if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { moveDir.y = +1; isMoving = true; } if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { moveDir.y = -1; isMoving = true; } if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { moveDir.x = -1; isMoving = true; } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { moveDir.x = +1; isMoving = true; } moveDir.Normalize(); float moveSpeed = 50f; Vector3 targetMoveToPosition = objectTransform.GetPosition() + moveDir * moveSpeed * Time.deltaTime; // Test if can move there raycastHit = Physics2D.Raycast(GetPosition() + moveDir * .1f, moveDir, Vector3.Distance(GetPosition(), targetMoveToPosition)); if (raycastHit.collider != null) { // Hit something } else { // Can move, no wall objectTransform.SetPosition(targetMoveToPosition); } if (isMoving) { Dirt_Handler.SpawnInterval(GetPosition(), moveDir * -1f); } // Update Feet unitSkeletonCompositeWalker_Feet.UpdateBodyParts(isMoving, moveDir); if (canShoot) { // Update Head and Body parts only when Not Shooting unitSkeletonCompositeWalker_BodyHead.UpdateBodyParts(isMoving, aimDir); } }); }
public void SetAimTarget(Vector3 targetPosition) { aimDir = (targetPosition - vObject.GetPosition()).normalized; unitSkeletonCompositeWeapon.SetAimTarget(aimDir); }
// Use this for initialization private void Start() { V_Object vObject = CreateBasicUnit(transform, new Vector3(500, 680), 30f, GameAssets.i.m_MarineSpriteSheet); V_UnitAnimation unitAnimation = vObject.GetLogic <V_UnitAnimation>(); V_UnitSkeleton unitSkeleton = vObject.GetLogic <V_UnitSkeleton>(); //V_IObjectWalker walker = vObject.GetLogic<V_IObjectWalker>(); V_IObjectTransform objectTransform = vObject.GetLogic <V_IObjectTransform>(); bool canShoot = true; V_UnitSkeleton_Composite_Weapon unitSkeletonCompositeWeapon = new V_UnitSkeleton_Composite_Weapon(vObject, unitSkeleton, GameAssets.UnitAnimEnum.dMarine_AimWeaponRight, GameAssets.UnitAnimEnum.dMarine_AimWeaponRightInvertV, GameAssets.UnitAnimEnum.dMarine_ShootWeaponRight, GameAssets.UnitAnimEnum.dMarine_ShootWeaponRightInvertV); vObject.AddRelatedObject(unitSkeletonCompositeWeapon); unitSkeletonCompositeWeapon.SetActive(); V_UnitSkeleton_Composite_Walker unitSkeletonCompositeWalker_BodyHead = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "Body", "Head" }); vObject.AddRelatedObject(unitSkeletonCompositeWalker_BodyHead); V_UnitSkeleton_Composite_Walker unitSkeletonCompositeWalker_Feet = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "FootL", "FootR" }); vObject.AddRelatedObject(unitSkeletonCompositeWalker_Feet); FunctionUpdater.Create(() => { Vector3 targetPosition = UtilsClass.GetMouseWorldPosition(); Vector3 aimDir = (targetPosition - vObject.GetPosition()).normalized; unitSkeletonCompositeWeapon.SetAimTarget(targetPosition); if (canShoot && Input.GetMouseButton(0)) { // Shoot canShoot = false; // Replace Body and Head with Attack unitSkeleton.ReplaceBodyPartSkeletonAnim(GameAssets.UnitAnimTypeEnum.dMarine_Attack.GetUnitAnim(aimDir), "Body", "Head"); // Shoot Composite Skeleton unitSkeletonCompositeWeapon.Shoot(targetPosition, () => { canShoot = true; }); // Add Effects Vector3 shootFlashPosition = vObject.GetLogic <V_UnitSkeleton>().GetBodyPartPosition("MuzzleFlash"); if (OnShoot != null) { OnShoot(this, new OnShootEventArgs { gunEndPointPosition = shootFlashPosition, shootPosition = targetPosition }); } //Shoot_Flash.AddFlash(shootFlashPosition); //WeaponTracer.Create(shootFlashPosition, targetPosition); } // Manual Movement bool isMoving = false; Vector3 moveDir = new Vector3(0, 0); if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { moveDir.y = +1; isMoving = true; } if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { moveDir.y = -1; isMoving = true; } if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { moveDir.x = -1; isMoving = true; } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { moveDir.x = +1; isMoving = true; } moveDir.Normalize(); objectTransform.SetPosition(objectTransform.GetPosition() + moveDir * 50f * Time.deltaTime); /* * if (isMoving) { * unitSkeleton.ReplaceBodyPartSkeletonAnim(GameAssets.UnitAnimTypeEnum.dBareHands_Walk.GetUnitAnim(moveDir), "FootL", "FootR"); * if (canShoot) { * unitSkeleton.ReplaceBodyPartSkeletonAnim(GameAssets.UnitAnimTypeEnum.dBareHands_Walk.GetUnitAnim(aimDir), "Body", "Head"); * } * } else { * unitSkeleton.ReplaceBodyPartSkeletonAnim(GameAssets.UnitAnimTypeEnum.dBareHands_Idle.GetUnitAnim(moveDir), "FootL", "FootR"); * if (canShoot) { * unitSkeleton.ReplaceBodyPartSkeletonAnim(GameAssets.UnitAnimTypeEnum.dBareHands_Idle.GetUnitAnim(aimDir), "Body", "Head"); * } * }*/ if (isMoving) { Dirt_Handler.SpawnInterval(GetPosition(), moveDir * -1f); } // Update Feet //unitSkeletonCompositeWalker_Feet.UpdateBodyParts(walker.GetLastMoveDir()); unitSkeletonCompositeWalker_Feet.UpdateBodyParts(isMoving, moveDir); if (canShoot) { // Update Head and Body parts only when Not Shooting unitSkeletonCompositeWalker_BodyHead.UpdateBodyParts(isMoving, aimDir); } }); }