public MoveToDestinationSystem() { foreach (GameObject go in _randomMovingGO) { MoveToDestination move = go.GetComponent <MoveToDestination>(); Transform tr = go.GetComponent <Transform>(); move.currentDestination = tr.position; } }
private void DoneMoving(MoveToDestination script) { if (charAnimator != null && useMoveSpeedAnimation) { charAnimator.ChangeToIdle(); } int uniqueID = script.UniqueID; DestroyImmediate(script); SendOverStatusToPlayer(uniqueID); }
private void onGOEnter(GameObject go) { MoveToDestination move = go.GetComponent <MoveToDestination>(); Transform tr = go.GetComponent <Transform>(); Boundaries bound = _boundariesGO.First().GetComponent <Boundaries> (); move.topLeftLimit = bound.topLeft.position; move.bottomRightLimit = bound.bottomRight.position; move.currentDestination = GetRandomPositionRange(bound.topLeft.position, bound.bottomRight.position); tr.rotation = Quaternion.LookRotation(Vector3.forward, move.currentDestination - tr.position); tr.rotation *= Quaternion.AngleAxis(90f, Vector3.forward); }
protected override void onProcess(int familiesUpdateCount) { foreach (GameObject go in _randomMovingGO) { MoveToDestination move = go.GetComponent <MoveToDestination>(); Transform tr = go.GetComponent <Transform>(); if (Vector3.Distance(tr.position, move.currentDestination) > .1f) { Vector3 movement = (move.currentDestination - tr.position).normalized; movement.Scale(new Vector3(1f, 1f, 0f)); tr.position += movement * move.speed * Time.fixedDeltaTime; } } }
public InputProcessor( Main main, Camera camera, Entity player, List <Interactable> interactables, EntityConfig entityConfig) { this.main = main; this.camera = camera; layerMask = 1 << LayerMask.NameToLayer("TouchInputRaycastable"); this.player = player; previousMove = new MoveToDestination(player, player.Location); this.interactables = interactables; this.entityConfig = entityConfig; }
protected override void onProcess(int familiesUpdateCount) { foreach (GameObject go in _randomMovingGO) { MoveToDestination move = go.GetComponent <MoveToDestination>(); Transform tr = go.GetComponent <Transform>(); if (Vector3.Distance(move.currentDestination, tr.position) < .1f) { move.currentDestination = GetRandomPositionRange(move.topLeftLimit, move.bottomRightLimit); tr.rotation = Quaternion.LookRotation(Vector3.forward, move.currentDestination - tr.position); tr.rotation *= Quaternion.AngleAxis(90f, Vector3.forward); } } }
/// <summary> /// Spawns an object at a random position. Calls EditEffectGroup with the list of effects on the appropriate position for the spawned object. /// </summary> /// <param name="effects">What effects to add to/remove from the object.</param> /// <returns></returns> public bool SpawnObject(List <EffectGroup> effects) { int rowToSpawn = SelectRow(); if (rowToSpawn == -1) { return(false); } int rowPosition = GetRowLengths()[rowToSpawn]; Vector3 spawnPos = GetObjectInitialPosition(rowToSpawn); Vector3 destPos = GetObjectFinalPosition(rowToSpawn, rowPosition); List <EffectGroup> groups = GetEffectGroup(rowToSpawn, rowPosition); cubes[rowToSpawn][rowPosition] = GameObject.Instantiate(placeholder, spawnPos, Quaternion.identity, transform); // cubes[rowToSpawn][rowPosition] = GameObject.Instantiate(cube, spawnPos, Quaternion.identity, transform); GameObject go = cubes[rowToSpawn][rowPosition]; go.transform.localPosition = spawnPos; GameObject temp = GameObject.Instantiate(cube, new Vector3(), Quaternion.identity, go.transform); temp.transform.localPosition = new Vector3(0, 0, -(transform.position.z + (cubeSize / 2f))); go.transform.localScale = scale; go.AddComponent <MoveToDestination>(); MoveToDestination mtd = go.GetComponent <MoveToDestination>(); mtd.SetDestination(destPos); if (effects.Count > 0) { EditEffectGroup(rowToSpawn, rowPosition, effects); } foreach (EffectGroup eg in groups) { eg.AddObjectToGroup(go); } return(true); }
// Start is called before the first frame update void Start() { SetupEffectGroups(); cubes = new GameObject[canvasHeight][]; // if (groupDistribution.Count() != canvasHeight) { // Debug.LogWarning("Group dist size height doesn't match given canvas size"); // } for (int i = 0; i < canvasHeight; i++) { cubes[i] = new GameObject[canvasWidth]; // if (groupDistribution[i].Count != canvasWidth) { // Debug.LogWarning ("Group dist size width doesn't match given canvas size"); // } } scale = new Vector3(cubeSize * cubePercentage, cubeSize * cubePercentage, cubeSize * cubePercentage); MoveToDestination.SetSpeed(cubeSpeed); }
public override void PlayAction(int uniqueID) { if (charToMove != null) { MoveToDestination existentScript = charToMove.GetComponent <MoveToDestination> (); if (existentScript == null) { CharacterController charCont = charToMove.GetComponent <CharacterController> (); SnapToGround snap = charToMove.GetComponent <SnapToGround> (); if (ignoreCollisions) { if (snap != null && snap.enabled) { snap.enabled = false; } } else { if (charCont == null) { charToMove.gameObject.AddComponent <CharacterController> (); } if (snap == null) { charToMove.gameObject.AddComponent <SnapToGround> (); } if (!snap.enabled) { snap.enabled = true; } } if (moveSpeed == MoveSpeed.Teleport) { Debug.Log("TELEPORTING"); charToMove.transform.position = destination.position; SendOverStatusToPlayer(uniqueID); } else { if (ignoreCollisions) { if (snap != null) { snap.enabled = false; } } MoveToDestination script = charToMove.gameObject.AddComponent <MoveToDestination> (); script.UniqueID = uniqueID; script.Script = this; script.Destination = destination.position; script.Speed = moveSpeed == MoveSpeed.Walk ? ControllableCharacter.DEFAULT_WALKING_SPEED : moveSpeed == MoveSpeed.Run ? Run.DEFAULT_RUNNING_SPEED : customSpeed; script.IgnoreCollisions = ignoreCollisions; script.IgnoreHeightPosition = ignoreHeightPosition; if (charAnimator != null) { if (useMoveSpeedAnimation) { charAnimator.UpdateCharacterParams((destination.position - charToMove.transform.position).normalized, true, moveSpeed == MoveSpeed.Run || moveSpeed == MoveSpeed.Custom && customSpeed >= Run.DEFAULT_RUNNING_SPEED); } else { charAnimator.ChangeCharacterState(anim); } } } } else { SendOverStatusToPlayer(uniqueID); } } else { SendOverStatusToPlayer(uniqueID); } }