void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            if (buildable.IsBuilding())
            {
                return;
            }

            float game_speed = TheGame.Get().GetGameTimeSpeedPerSec();

            if (!IsFullyGrown() && grow_time > 0.001f)
            {
                growth_progress += game_speed * boost_mult * Time.deltaTime;
                PlayerData.Get().SetCustomValue(GetProgressUID(), Mathf.RoundToInt(growth_progress));

                if (growth_progress > grow_time)
                {
                    GrowPlant();
                    return;
                }
            }

            if (!has_fruit && fruit != null)
            {
                fruit_progress += game_speed * boost_mult * Time.deltaTime;
                PlayerData.Get().SetCustomValue(GetProgressUID(), Mathf.RoundToInt(fruit_progress));

                if (fruit_progress > fruit_grow_time)
                {
                    GrowFruit();
                    return;
                }
            }

            //Boost stop
            if (boost_timer > 0f)
            {
                boost_timer -= game_speed * Time.deltaTime;
                if (boost_timer <= 0.01f)
                {
                    boost_mult = 1f;
                }
            }

            //Display
            if (fruit_model != null && has_fruit != fruit_model.gameObject.activeSelf)
            {
                fruit_model.gameObject.SetActive(has_fruit);
            }
        }
Example #2
0
        private void Start()
        {
            //select.onUse += OnUse;
            select.RemoveGroup(fire_group);
            buildable.onBuild += OnBuild;

            if (!construction.was_spawned && !buildable.IsBuilding())
            {
                fuel = start_fuel;
            }
            if (PlayerData.Get().HasCustomValue(GetFireUID()))
            {
                fuel = PlayerData.Get().GetCustomValue(GetFireUID());
            }
        }
        //Trigger will 'close' the trap and damage the animal triggering it
        public void Trigger(Character triggerer)
        {
            if (buildable != null && buildable.IsBuilding())
            {
                return;
            }

            if (!triggered && trigger_timer > 2f)
            {
                triggered = true;
                active_model.SetActive(false);
                triggered_model.SetActive(true);

                if (triggerer)
                {
                    triggerer.GetDestructible().TakeDamage(damage);
                }
            }
        }
        private void FixedUpdate()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            if (!move_enabled)
            {
                return;
            }

            if (buildable && buildable.IsBuilding())
            {
                return;
            }

            Vector3 tmove     = Vector3.zero;
            bool    is_flying = fall_speed < 0.01f;

            if (!IsDead())
            {
                //Destination default
                move_target_avoid = move_target;

                //Navmesh
                if (use_navmesh && follow_path && !direct_move && is_moving && path_index < nav_paths.Length)
                {
                    move_target_avoid = nav_paths[path_index];
                    Vector3 dir_total = move_target_avoid - transform.position;
                    dir_total.y = 0f;
                    if (dir_total.magnitude < moving_threshold * 2f)
                    {
                        path_index++;
                    }
                }

                //Navmesh
                if (use_navmesh && is_moving && !direct_move)
                {
                    Vector3 path_dir     = path_destination - transform.position;
                    Vector3 nav_move_dir = move_target - transform.position;
                    float   dot          = Vector3.Dot(path_dir.normalized, nav_move_dir.normalized);
                    if (dot < 0.7f)
                    {
                        CalculateNavmesh();
                    }
                }

                //Avoiding
                if (is_moving && !direct_move && avoid_obstacles && !use_navmesh && !HasReachedMoveTarget(1f))
                {
                    move_target_avoid = FindAvoidMoveTarget(move_target);
                }

                //Moving
                if (is_moving)
                {
                    Vector3 move_dir_total = move_target - transform.position;
                    Vector3 move_dir_next  = move_target_avoid - transform.position;
                    Vector3 move_dir       = move_dir_next.normalized * Mathf.Min(move_dir_total.magnitude, 1f);
                    tmove = move_dir.normalized * Mathf.Min(move_dir.magnitude, 1f) * move_speed;
                }

                //Facing
                if (IsMoving())
                {
                    Vector3 tface = new Vector3(moving.x, 0f, moving.z);
                    facing = tface.normalized;
                }

                //Rotation
                Quaternion targ_rot = Quaternion.LookRotation(facing, Vector3.up);
                Quaternion nrot     = Quaternion.RotateTowards(rigid.rotation, targ_rot, rotate_speed * Time.fixedDeltaTime);
                rigid.MoveRotation(nrot);

                //Slope climbing
                float slope_angle = Vector3.Angle(ground_normal, Vector3.up);
                bool  up_hill     = Vector3.Dot(transform.forward, ground_normal) < -0.1f; //Climbing up
                if (up_hill && !is_flying && slope_angle > slope_angle_max)
                {
                    tmove = Vector3.zero; // Slope too high
                }
            }

            //Falling
            if (!is_grounded && !is_flying)
            {
                tmove += Vector3.down * fall_speed;
            }

            //Cancel falling
            if (is_grounded && tmove.y < 0f)
            {
                tmove.y = 0f;
            }

            //Adjust to slope
            if (is_grounded && !is_flying)
            {
                tmove = Vector3.ProjectOnPlane(tmove.normalized, ground_normal).normalized *tmove.magnitude;
            }

            //Ground distance average
            if (is_grounded)
            {
                grounded_dist_average = Mathf.MoveTowards(grounded_dist_average, grounded_dist, 5f * Time.fixedDeltaTime);
            }

            //Adjust ground
            //if (is_grounded && grounded_dist_average > grounded_dist)
            //    transform.position = Vector3.MoveTowards(transform.position, transform.position + Vector3.up * grounded_dist, 1f * Time.fixedDeltaTime);

            moving         = Vector3.Lerp(moving, tmove, 10f * Time.fixedDeltaTime);
            rigid.velocity = moving;

            //Check the average traveled movement (allow to check if character is stuck)
            Vector3 last_frame_travel = transform.position - prev_pos;

            move_average = Vector3.MoveTowards(move_average, last_frame_travel, 2f * Time.fixedDeltaTime);
            prev_pos     = transform.position;
            is_stuck     = is_moving && move_average.magnitude <0.02f && move_timer> 0.5f;
        }
 public bool CanBuild()
 {
     return(current_buildable != null && current_buildable.IsBuilding() && build_timer > 0.5f);
 }
Example #6
0
 public bool IsBuilt()
 {
     return(!IsDead() && !buildable.IsBuilding());
 }