// Start is called before the first frame update
 void Awake()
 {
     character = GetComponent <CharacterController>();
     weapon    = GetComponent <WeaponController>();
     curve     = GetComponent <CurveController>();
     instance  = this;
 }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        //mesh_transform.parent = transform;

        // set camera direction to use as reference for player's forward direction
        set_camera_direction(player_camera.transform.forward);

        Debug.DrawRay(transform.position, camera_direction * 5, Color.blue);

        // get user input
        user_input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        // transform user input relative to the direction of camera, use a extra transform for convinience
        move_direction_calculator.position = transform.position;
        move_direction_calculator.forward  = camera_direction;
        user_input = move_direction_calculator.TransformDirection(user_input);
        user_input.Normalize();

        Debug.DrawRay(transform.position, user_input * 5, Color.green);

        // set the player_move_vector to appropriate direction and value
        player_move_vector  = user_input;
        player_move_vector *= player_move_speed;

        //


        // apply movement
        //character_controller.SimpleMove (player_move_vector);
        CurveController.Rotate(0, Mathf.Abs(Vector3.Angle(camera_last_position - player_last_position, camera_last_position - transform.position)) * (Input.GetAxisRaw("Horizontal")), 0);

        player_last_position   = transform.position;
        camera_last_position   = player_camera.transform.position;
        camera_last_position.y = player_last_position.y;

        // set animations
        // must be changed

        print(player_move_vector.sqrMagnitude);
        if (player_move_vector.sqrMagnitude > 0.01f)
        {
            //animation_controller.applyRootMotion = false;
            //mesh_target_rotation = Quaternion.LookRotation (player_move_vector, mesh_transform.up);

            animation_controller.SetFloat("Rotation", Mathf.Clamp(Vector3.SignedAngle(mesh_transform.forward, player_move_vector, Vector3.up) / 90.0f * 1.5f, -1.0f, 1.0f));
            //mesh_transform.rotation = Quaternion.Lerp (mesh_transform.rotation, mesh_target_rotation, Time.deltaTime * 10f);
        }


        animation_controller.SetFloat("MoveSpeed", user_input.sqrMagnitude);
        if (Input.GetButtonDown("Jump"))
        {
            animation_controller.SetTrigger("Jump");
        }
        //transform.position = Vector3.Lerp (transform.position, mesh_transform.position, Time.deltaTime * 2f);
        transform.position = mesh_transform.position;
    }
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.GetComponent <CurveController>() != null)
        {
            curveControllerToReset = other.gameObject.GetComponent <CurveController>();
            curveControllerToReset.PlayDownSound();
            targetRotation     = new Vector3(curveControllerToReset.transform.rotation.x, 180, curveControllerToReset.transform.rotation.z);
            shouldMoveFishBack = true;
            timeElapsed        = 0;



            // other.gameObject.GetComponent<CurveController>().FollowCurve();
        }
    }
    // Update is called once per frame
    void Update()
    {
        // set camera direction to use as reference for player's forward direction
        set_camera_direction(player_camera.transform.forward);

        Debug.DrawRay(transform.position, camera_direction * 5, Color.blue);

        // get user input
        user_input = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        // transform user input relative to the direction of camera, use a extra transform for convinience
        move_direction_calculator.position = transform.position;
        move_direction_calculator.forward  = camera_direction;
        user_input = move_direction_calculator.TransformDirection(user_input);
        user_input.Normalize();

        Debug.DrawRay(transform.position, user_input * 5, Color.green);

        // set the player_move_vector to appropriate direction and value
        player_move_vector  = user_input;
        player_move_vector *= player_move_speed;

        //
        player_last_position   = transform.position;
        camera_last_position   = player_camera.transform.position;
        camera_last_position.y = player_last_position.y;

        // apply movement
        CurveController.Rotate(0, Mathf.Abs(Vector3.Angle(camera_last_position - player_last_position, camera_last_position - transform.position)) * (Input.GetAxisRaw("Horizontal")), 0);


        // set animations
        // must be changed


        //if(player_move_vector.sqrMagnitude > 0.1f)
        //	mesh_transform.rotation = Quaternion.LookRotation( player_move_vector, mesh_transform.up);


        animation_controller.SetFloat("speed", user_input.sqrMagnitude);
        animation_controller.SetFloat("direction", Input.GetAxis("Horizontal"));
    }
Beispiel #5
0
    // Update is called once per frame
    void LateUpdate()
    {
        // direct mapping to user input, maybe jerky but accurate
        if (!smoothing)
        {
            // horizontal movement
            CurveController.Rotate(0, Input.GetAxisRaw("Mouse X") * mouse_horizontal_speed * Time.deltaTime, 0, smoothing_value);
            // vertical movment
            // calculate new t_value
            t_value += Input.GetAxisRaw("Mouse Y") * Time.deltaTime * mouse_vertical_speed;
            t_value  = Mathf.Clamp(t_value, 0f, 1f);
            camera_target_position = camera_curve.GetPoint(t_value);
        }
        else         // smoothened camera movement
        {
            // horizontal movement
            // calculates proper rotation values, and updates in during the next update
            CurveController.Rotate(0, Input.GetAxisRaw("Mouse X") * mouse_horizontal_speed * Time.deltaTime, 0, smoothing_value);
            // vertical movment
            // calculate new target t value and lerp towards it
            smooth_target_t_value += Input.GetAxisRaw("Mouse Y") * Time.deltaTime * mouse_vertical_speed;
            smooth_target_t_value  = Mathf.Clamp(smooth_target_t_value, 0f, 1f);

            t_value = Mathf.Lerp(t_value, smooth_target_t_value, smoothing_value * Time.deltaTime);
            camera_target_position = camera_curve.GetPoint(t_value);
        }

        // change filed of view depending on pitch
        target_field_of_view = min_field_of_view + (max_field_of_view - min_field_of_view) * t_value;
        this_camera_reference.fieldOfView = target_field_of_view;

        // place camera at target
        transform.position = camera_target_position;
        // camera normally looks at the direction of just above the player head
        transform.LookAt(target);
    }
 // Use this for initialization
 void Awake()
 {
     _instance = this;
     smooth_target_rotation = transform.rotation;
 }