public override void BeginToUse(Actor actorUsing, OnUsed <Actor> onUseBegin, OnUsed <Actor> onDynamicItemUsed) { //Casting projectile here this.actorUsing = actorUsing; onUseOver = onDynamicItemUsed; attack = actorUsing.currentAttack; projectileTypeThrown = actorUsing.currentAttack.projectiles; actorHadAuthority = actorUsing.hasAuthority(); gameObjectInstanceId = actorUsing.gameObject.GetInstanceID(); ownerId = actorUsing.ownerId; //Debug.LogError("PProjectile to throw type "+projectileTypeThrown.ToString()); GameObject gToSpawn = Resources.Load(projectileTypeThrown.ToString()) as GameObject; if (gToSpawn == null) { Debug.LogError("gToSpawn is null"); return; } liveProjectile = GridManager.InstantiateGameObject(gToSpawn).GetComponent <ProjectileUtil>(); liveProjectile.transform.position = GridManager.instance.cellToworld(actorUsing.positionToSpawnProjectile); initPos = liveProjectile.transform.position; finalPos = actorUsing.actorTransform.position + (liveProjectile.projectileTileTravelDistance * GridManager.instance.GetFacingDirectionOffsetVector3(actorUsing.Facing)); tileMovementDirection = actorUsing.Facing; liveProjectile.Initialise(this); //if (projectileTypeThrown==EnumData.Projectiles.FlamePillar) //{ // liveProjectile.transform.position = actorUsing.actorTransform.position + GridManager.instance.GetFacingDirectionOffsetVector3(actorUsing.Facing); // finalPos = actorUsing.actorTransform.position + GridManager.instance.GetFacingDirectionOffsetVector3(actorUsing.Facing) + (liveProjectile.projectileTileTravelDistance * GridManager.instance.GetFacingDirectionOffsetVector3(actorUsing.Facing)); //} }
public void ProjectileUnitEnter(ProjectileUtil projectileUtil, Vector3Int portalCellPosition) { if (portalEntranceDic.ContainsKey(portalCellPosition)) { if (projectileUtil.pU.ownerId == portalEntranceDic[portalCellPosition].portalOwner) { TeleportProjectiles(projectileUtil, portalEntranceDic[portalCellPosition].portalOutlet); } } }
void TeleportProjectiles(ProjectileUtil projectileUtil, Vector3Int portalCellPosition) { float distanceTravelled = Vector3.Distance(projectileUtil.pU.initPos, projectileUtil.transform.position); float totalDistanceToTravelled = Vector3.Distance(projectileUtil.pU.initPos, projectileUtil.pU.finalPos); float distanceLeft = totalDistanceToTravelled - distanceTravelled; projectileUtil.pU.initPos = GridManager.instance.cellToworld(portalCellPosition); projectileUtil.pU.finalPos = projectileUtil.pU.initPos + (distanceLeft * GridManager.instance.GetFacingDirectionOffsetVector3(projectileUtil.pU.tileMovementDirection)); projectileUtil.transform.position = GridManager.instance.cellToworld(portalCellPosition); }