Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 unity_0yC6vhmB0khegg · Aug 10, 2019 at 07:07 AM · mathplayer movement

How to control horizontal movement while making Sine wave pattern?

Hi,

For a very small personal project in AR i'm trying to control the movement of a sphere(Only Horizontally) while it's making a Sinewave pattern.

For example:

Sphere is going from point A to point B with a sinewave pattern. I press the right button (on the touchscreen of the phone) The spere moves to the right but it maintains it's wave without chaging magnitude, frequency, etc.

I've tried with a Sinewave script:

  using UnityEngine;
  using System.Collections;
  
  public class Projectile : MonoBehaviour {
      
      public float MoveSpeed = 5.0f;
  
      public float frequency = 20.0f;  // Speed of sine movement
      public float magnitude = 0.5f;   // Size of sine movement
      private Vector3 axis;
  
      private Vector3 pos;
  
      void Start () {
          pos = transform.position;
          //DestroyObject(gameObject, 1.0f);
          axis = transform.right;  // May or may not be the axis you want
          
      }
      
      void Update () {
          pos += transform.up * Time.deltaTime * MoveSpeed;
          transform.position = pos + axis * Mathf.Sin (Time.time * frequency) * magnitude;
      }
  }

And then adding a movement script to the camera:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Movement : MonoBehaviour {
     //variables
     public float moveSpeed = 300;
     public GameObject character;
 
     private Rigidbody characterBody;
     private float ScreenWidth;
 
 
     // Use this for initialization
     void Start () {
         ScreenWidth = Screen.width;
         characterBody = character.GetComponent<Rigidbody>();
     }
     
     // Update is called once per frame
     void Update () {
         int i = 0;
         //loop over every touch found
         while (i < Input.touchCount) {
             if (Input.GetTouch (i).position.x > ScreenWidth / 2) {
                 //move right
                 RunCharacter (1.0f);
             }
             if (Input.GetTouch (i).position.x < ScreenWidth / 2) {
                 //move left
                 RunCharacter (-1.0f);
             }
             ++i;
         }
     }
     void FixedUpdate(){
         #if UNITY_EDITOR
         RunCharacter(Input.GetAxis("Horizontal"));
         #endif
     }
 
     private void RunCharacter(float horizontalInput){
         //move player
         characterBody.AddForce(new Vector2(horizontalInput * moveSpeed * Time.deltaTime, 0));
 
     }
 }
 

But they override each other and they don't work simultaneously.

Anyone got an idea?

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

187 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

Related Questions

How do I do my camera player look at an specific direction when key pressed 0 Answers

I use click to move, but don't want my player to rotate... How to fix this rotation? 1 Answer

Jump button doesn't work 1 Answer

how to calculate the angle between two vectors? 6 Answers

Adjusting viewing angle without distortion. 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