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 taxcollection · Jun 13, 2017 at 03:46 PM · movementbasichelloworld

Why is going one direction faster

Okay so i have a simple basic code for moving ,]------------------

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Ballcontroller2 : MonoBehaviour {

 public float movespeed;
 private Rigidbody myrigidbody;

 private Vector3 moveInput;
 private Vector3 moveVelocity;


 // Use this for initialization
 void Start () {
     myrigidbody = GetComponent<Rigidbody> ();
     
 }
 
 // Update is called once per frame
 void Update () {
     moveInput = new Vector3 (Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
     moveVelocity = moveInput * movespeed;
 }

 void FixedUpdate () {
     myrigidbody.velocity = moveVelocity;
 }

}


but everytime i press up and left at the same time the speed is faster than if i press up by or left by itself

is there a way to fix that so that the speed is the same? picture below should help what im saying by up-left

alt text

Thanks in advance!

untitled.png (266.9 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Leucaruth · Jun 13, 2017 at 04:20 PM

Hi.

Tthis is a common problem. It's related to the pythagorean theorem.

You must think with directions as if they were inside a circle, as you are doing right now it's as if they were inside a square. This means that when you push diagonally you are creating a vector which magnitude is 1.4142, and when you are pushing only one axis, horizontal or vertical, you are creating a vector which magnitude is only 1.

You can see how this works in this image:

alt text

To make your movement homogeneous, you need to "normalize" your vector, this is done automatically by unity if you write ".normalize" after your vector, so if you change your line of code:

moveVelocity = moveInput * movespeed;

with this one:

moveVelocity = moveInput.normalized * movespeed;

your problem will be solved.

If you are curious I recommend you to search more about vectors as you will need a good knowledge about them in Unity.


both.png (5.1 kB)
Comment
Add comment · Show 2 · 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 taxcollection · Jun 13, 2017 at 04:40 PM 0
Share

Thanks a lot! it worked just fine and i will take your advice and do more research on Vectors. Once again thank you for your help

     :) byrd
avatar image Leucaruth taxcollection · Jun 13, 2017 at 11:53 PM 0
Share

You are welcome ^^. I'm glad if I was of some help.

avatar image
0

Answer by taxcollection · Jun 13, 2017 at 03:47 PM

Btw im very new to unity :)

Comment
Add comment · 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

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

90 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

Related Questions

Make GameObject move in one direction continuously on key press on C# 1 Answer

How can I properly integrate rotation to a character? 0 Answers

Basic AI Movement C# 3 Answers

Constrained Movement for 2.5D character 1 Answer

How to stop object from rotating during movement (Javascript) 1 Answer


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