Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by leozaur · May 05, 2021 at 09:43 PM · movementmobilemovement scriptswipemovements

Unusual movement script. Any ideas how to do that?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
  
 public class Move : MonoBehaviour
 {
     public float speed = 3f;
  
     private bool moving = false;
    
     public float zPos, xPos;
     public bool move = false;
     public SwipeManager swipe;
     private bool IsMoving = false;
     private Animator animator;
  
     // Start is called before the first frame update
     void Start()
     {
         xPos = ChangeXPos(1);
         zPos = ChangeZPos(1);
         animator = transform.GetChild(0).GetComponent<Animator>();
     }
  
  
     // Update is called once per frame
     void Update()
     {
         int swipeDir = swipe.GetSwipeDirection();
         Debug.Log(swipe.GetSwipeDirection());
         switch (swipeDir)
         {
             case 1:
                 animator.SetInteger("direction", 1);
                
                 break;
             case 2:
                 animator.SetInteger("direction", 2);
                 break;
             case 3:
                 animator.SetInteger("direction", 3);
                 break;
             case 4:
                 animator.SetInteger("direction", 4);
                 break;
             case 0:
                 animator.SetInteger("direction", 0);
                 break;
         }
      
        
  
        
        
      
     }
     bool  Step (Vector3 targetPosition)
     {
         bool success = false;
      
         transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
        
         if(transform.position == targetPosition)
         {
             success = true;
          
         }
         return success;
  
     }
     bool ZStep(float zPos)
     {
         bool complete = false;
         moving = true;
         if(Step(new Vector3(transform.position.x, transform.position.y, zPos)))
         {
             moving = false;
             complete = true;
            
         }
         return complete;
     }
     bool XStep(float xPos)
     {
         bool complete = false;
         moving = true;
         if (Step(new Vector3(xPos, transform.position.y, transform.position.z)))
         {
             complete = true;
             moving = false;
         }
         return complete;
     }
     float ChangeZPos(int dir)
     {
        
         if(dir == 1)
         {
             return transform.position.z + 5f;
         } else
         {
             return transform.position.z - 5f;
         }
  
     }
     float ChangeXPos(int dir)
     {
         if(dir == 1)
         {
             return transform.position.x + 5f;
         } else
         {
             return transform.position.x - 5f;
         }
     }
     IEnumerator wait(float wait)
     {
         yield return new WaitForSeconds(wait);
     }
 }

Can someone please help me to make a script that dmoves the player for +5 or -5 by each coordinate when player inputs a swipe(1 - up, 2 - down, 3 - left, 4 - right, accesed by GetSwipeDirection() in Update()), so when player input for example 1 player must move to transform.position.z + 5f smoothly using moveTowards. And yep that's not even all. How to check when the player is moving up for example that if on the right or left there is nothing then stop. I am really stuck with that.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

261 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My controls are wierd 0 Answers

Make the Player unable to move to opposite direction 1 Answer

How to throw an object while swiping and after 0 Answers

Why is my ball flying away? 0 Answers

Swipe camera rotation controller (HELP) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges