Exemple #1
0
 void Update()
 {
     if (touchAxis.GetAxis().sqrMagnitude != 0)
     {
         Quaternion targetRot = Quaternion.Euler(0, 0, -Mathf.Atan2(touchAxis.GetAxis().x, touchAxis.GetAxis().y) * Mathf.Rad2Deg);
         transform.rotation  = Quaternion.Lerp(transform.rotation, targetRot, rotateSpeed * Time.deltaTime);
         transform.position += transform.up * touchAxis.GetAxis().sqrMagnitude *speed *Time.deltaTime;
     }
 }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (touchAxisControl.IsTouching())
        {
            m_TargetXY = new Vector3(Mathf.Clamp(ship.localPosition.x + touchAxisControl.GetAxis("Horizontal"), -xRange, xRange),
                                     Mathf.Clamp(ship.localPosition.y + touchAxisControl.GetAxis("Vertical"), -yRange, yRange));
        }
        Vector2 lerpPos = Vector2.Lerp(new Vector2(ship.localPosition.x, ship.localPosition.y), m_TargetXY, snapSpeed);

        ship.localEulerAngles = new Vector3(Remap(ship.localPosition.y - m_TargetXY.y, -1, 1, -Mathf.Abs(pitchAndRollRange.x), Mathf.Abs(pitchAndRollRange.x)),
                                            ship.localEulerAngles.y,
                                            Remap(ship.localPosition.x - m_TargetXY.x, -1, 1, -Mathf.Abs(pitchAndRollRange.y), Mathf.Abs(pitchAndRollRange.y)));
        ship.localPosition = new Vector3(lerpPos.x, lerpPos.y, ship.localPosition.z);
    }
 void Update()
 {
     if (m_bAlive)
     {
         Vector3 pos = transform.position;
         pos.y = pos.y + speed * Time.deltaTime;
         pos.x = pos.x + m_Touch.GetAxis().x *touchSensitivity *Time.deltaTime;
         transform.position = pos;
     }
 }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        if (touchAxisControl.IsTouching())
        {
            if (!m_bHasBeenTouching)
            {
                m_bHasBeenTouching = true;
                m_InitialXY        = new Vector2(ship.localPosition.x, ship.localPosition.y);
            }
            m_TargetXY = new Vector3(Mathf.Clamp(m_InitialXY.x + touchAxisControl.GetAxis("Horizontal") * xRange, -xRange, xRange),
                                     Mathf.Clamp(m_InitialXY.y + touchAxisControl.GetAxis("Vertical") * yRange, -yRange, yRange));
        }
        else
        {
            m_bHasBeenTouching = false;
        }
        Vector2 lerpPos = Vector2.Lerp(new Vector2(ship.localPosition.x, ship.localPosition.y), m_TargetXY, snapSpeed);

        ship.localEulerAngles = new Vector3(Remap(ship.localPosition.y - m_TargetXY.y, -yRange, yRange, -30, 30),
                                            ship.localEulerAngles.y,
                                            Remap(ship.localPosition.x - m_TargetXY.x, -xRange, xRange, -90, 90));
        ship.localPosition = new Vector3(lerpPos.x, lerpPos.y, ship.localPosition.z);
    }
Exemple #5
0
    void Update()
    {
        Vector3 axis = touchAxis.GetAxis().ToVector3();

        if (axis.sqrMagnitude != 0)
        {
            transform.position += axis * speed * Time.deltaTime;
            dir = (axis.x > 0) ? initXScale : -initXScale;
            if (dir != cachedDir)
            {
                cachedDir = dir;
                transform.Scale(transform.localScale.With(x: dir), .25f);
            }
        }
    }
Exemple #6
0
    void Update()
    {
        if (m_TouchControl.IsTouching())
        {
            // Get the joystick value
            Vector3 val = Wrj.Utils.ToVector3(m_TouchControl.GetAxis());
            // The line/arrow position is inverted to point the direction the ball will be shot. It's doubled for improved visibility.
            Vector3 pos2 = transform.position + val * -2f;

            // Invert the force and save it globally so it's up-to-date upon untouch. Will be used as the basis of desired velocity.
            m_Force = -val;

            // Draw the indicator arrow
            m_Line.positionCount = 2;
            m_Line.SetPosition(0, transform.position);
            m_Line.SetPosition(1, pos2);
        }
    }
Exemple #7
0
    void Update()
    {
        Vector2 input         = touch.GetAxis();
        Vector3 adjustedInput = new Vector3(input.x, 0, input.y) * speed;

        transform.position += adjustedInput;
        Attractor nearestAttractor = null;
        float     nearestDistance  = 10f;

        foreach (Attractor attractor in attractors)
        {
            float distance = Vector3.Distance(transform.position, attractor.transform.position);
            if (distance < range)
            {
                attractor.transform.position += (transform.position - attractor.transform.position).normalized * distance.Remap(0, range, pull, pull * .5f) * Time.deltaTime;
                if (distance < nearestDistance)
                {
                    nearestDistance  = distance;
                    nearestAttractor = attractor;
                }
            }
        }
        if (nearestAttractor != null)
        {
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(nearestAttractor.transform.position - transform.position, Vector3.up), Time.deltaTime * rotationSpeed);
            if (particles != null && !particles.isPlaying)
            {
                particles.Play();
            }
        }
        else if (Vector3.Distance(lastPos, transform.position) > .05f)
        {
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(transform.position - lastPos, Vector3.up), Time.deltaTime * rotationSpeed);
            if (particles != null && particles.isPlaying)
            {
                particles.Stop();
            }
        }
        lastPos = transform.position;
    }