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 cooltrophygameing · Sep 21, 2019 at 03:45 AM · movementmobile devices

Is there a way to see if the Y axis is going up

Im making a mobile game for the first time and making movement. I want to see if there is some code that can see if the Y axis of the mouse position is going up or down. And if it is going up it moves the character up. I also want to do the same for X axis so is this possible?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mirage3d · Sep 21, 2019 at 07:11 AM

If what you need is to move the character, then you can use this code inside of the Update() function in a - preferably movement or controller - script attached to your character:

 private float speed = 4f;
 private Vector3 velocity = Vector3.zero;
 private RigidBody rigidBody;
 
 void Update() {
     // ...
     Vector3 forward = transform.forward * Input.GetAxis("Vertical");
     Vector3 right = transform.right * Input.GetAxis("Horizontal");
     velocity = (forward + right).normalized * speed;
     // do the actual movement in FixedUpdate()
 }
 
 void FixedUpdate() {
     transform.position += velocity * Time.fixedDeltaTime;
     // or you can set the velocity on the RigidBody, and let Physics do the movement:
     // rigidbody.velocity = velocity;
 }
Comment
Add comment · Show 5 · Share
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
avatar image cooltrophygameing · Sep 21, 2019 at 02:52 PM 0
Share

I don't understand what that code is. I know how to make pc movement. Im looking for mobile movement. I don't want any plungins though.

avatar image mirage3d · Sep 22, 2019 at 01:06 AM 0
Share

Sorry, my bad. Didn't understand your question. Saw "mouse" so I immediately thought "PC".

$$anonymous$$aybe you're asking about touches?

 // Vector2 result. handling first touch
 var movementDelta = Input.GetTouch(0).deltaPosition;
 
 var upPixels = movementDelta.x;        // negative if down
 var rightPixels = movementDelta.y;    // negative if left
 

more info: Unity Scripting API - Input.GetTouch

avatar image cooltrophygameing mirage3d · Sep 22, 2019 at 02:56 AM 0
Share

its fine. but i don't understand your code. i want to make it so that i can move my hand anywhere on the screen and the character moves in that direction and follows. can you give me any code to help with this and give me some explaining so i know what im doing. reading this i sound rude but im sorry i don't mean it that way.

avatar image mirage3d cooltrophygameing · Sep 22, 2019 at 03:25 AM 0
Share

no problem.

I think for me to give you full code might be an overkill here. I found a video that talks about handling touches in mobile games from Brackeys. He uses a system from the asset store. If it suits you, you could probably use the same. Otherwise you can easily replace the joystick code he uses with the Input.GetTouch[0].position or Input.GetTouch[0].deltaPosition like above.

https://www.youtube.com/watch?v=bp2PiFC9sSs

The idea is that you ask the Input manager for the touch events. These are returned as Touch structures that contain position and deltaPosition values among other things. you would do this in the Update() method, and then preform the actual move in the FixedUpdate() method since it makes more sense to move/transform your character during the physics update stage of the run loop. If you do that, then you need a variable to se in Update() and use that variable to move your object's transform.position in FixedUpdate().

Hope that helps.

Show more comments

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

240 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

Related Questions

Make character move up on Y axis as apposed to move forward in Z space when mobile device is tilted 2 Answers

Way to detect movement on mobile devices 0 Answers

How do I adjust code so gyro translates player to center position when device is being held in hands 1 Answer

the player input is jittery seems like glitching 0 Answers

movement control for IOS 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