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 /
avatar image
0
Question by lpflicke · Dec 30, 2016 at 02:41 PM · movement scriptjoystick3rd person controller

Joystick Movement problems

I am trying to make a mario-3D-world style game but am having problems with how Joystick input works in unity. The problem is that when aiming diagonally, the character moves quicker than not diagonally. When Drawing a ray from the character and the characters position + the joystick input, the ray is longer diagonally. I've tried to normalize it and then multiply that with a speed but that doesn't seem to do anything. Is there a way to counteract this?

Code:

 var rb : Rigidbody;
 var X_Input : float;
 var Z_Input : float;
 var Speed : float;
 var camDir : Vector3;
 var newVel : Vector3;
 
 
 function Start () {
     //simplifies getcomponent to only rb
     rb = GetComponent("Rigidbody");
     Speed = 20;
 }
 
 function Update ()
 {
     //Find Camera Direction
     camDir = Camera.main.transform.forward;
     //Set Camera Direction.y to 0 so movement not affected on y axis
     camDir.y = 0;
     camDir.Normalize();
     //find left and right of camera by using CameraDirection
     var camRight = new Vector3(camDir.z,0,-camDir.x);
     var playerUp = Vector3.up;
 
     //Joystick Input
     X_Input = Input.GetAxis("L_Joystick_Horizontal");
     Z_Input = -Input.GetAxis("L_Joystick_Vertical");
     //Set Old Movement to normal
     newVel = Vector3.zero;
     //Set Based on inputs
     newVel = new Vector3(camRight.x*X_Input,0,camDir.z*Z_Input);
     //Now only stores the DIRECTION of input(can control speed manually later)
     Vector3.Normalize(newVel);
     //Vector3.ClampMagnitude(newVel, 1);
 
     //Debug
     Debug.Log();
     Debug.DrawRay(transform.position,newVel,Color.green);
 }
 function FixedUpdate()
 {
     //Adds inputdirection*speed force to player
     rb.AddForce(newVel*Speed);
 }


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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Joystick unusual behavior on axis with almost the same script as W A S D 0 Answers

Touch buttons for step movememt 3 Answers

Android based ARCore example ObjectManipulation using Joystick Controller 0 Answers

How to remove the Vertical axis on Joystick? 1 Answer

Hello Im making a Game for mobile and want two floating joysticks one on either side of the screen. 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