Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 AceDawg45 · Jul 15, 2014 at 09:33 PM · 2dmovementtopdown

Help with topdown movement in Unity2d?

So, I have looked over the internet for a bit now, yet everything I try doesn't work. I put a movement script I have from a platformer onto the player, but I can only move it left and right. I am gonna post my code below, but my question is how to make it move up and down? Thanks for any help!

 using UnityEngine;
 using System.Collections;
 
 public class MoveTopDown : MonoBehaviour {
     
     public float speed =1.0f;
     public string axisName = "Horizontal";
 
     
     // Use this for initialization
     void Start () {
         
     }
     
     void Update ()
     {
 
     }
     
     
     
     // Update is called once per frame
     void FixedUpdate () {
         if (Input.GetAxis (axisName) > 0)
         {
             Vector3 newScale = transform.localScale;
             newScale.y = 1.0f;
             newScale.x = 1.0f;
             transform.localScale = newScale;
             
         } 
         else if (Input.GetAxis (axisName) < 0)
         {
             Vector3 newScale =transform.localScale;
             newScale.x = 1.0f;
             transform.localScale = newScale;        
             
         }
         
         
         transform.position += transform.right * Input.GetAxis (axisName) * speed * Time.deltaTime;    
     }
 }
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 robertbu · Jul 15, 2014 at 10:17 PM

You need to add a second axisName at the top of the file:

 public string axisName2 = "Vertical";

Then you need to insert this at line 40:

 transform.position += transform.up * Input.GetAxis(axisName2) * speed * Time.deltaTime;
Comment
Add comment · Show 3 · 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 AceDawg45 · Jul 15, 2014 at 10:32 PM 0
Share

Thanks, it sort of works, but it doesn't. It is just going up in down, in other words, just the y axis is moving. I need to be able to move the z axis. Any idea on how to do that?

avatar image robertbu · Jul 15, 2014 at 10:54 PM 0
Share

If you have oriented your camera to look down the 'y' axis for your top-down implementation, just change 'transform.up' to 'transform.forward':

  transform.position += transform.forward * Input.GetAxis(axisName2) * speed * Time.deltaTime;
avatar image AceDawg45 · Jul 15, 2014 at 11:06 PM 0
Share

Oh Wow thanks! Now I can get this project underway!

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

1 Person is following this question.

avatar image

Related Questions

2D Top Down Character Controller 1 Answer

2D Pathfinding Top Down 0 Answers

Top down 2d movement without being affected by rotation 2 Answers

How do I detect when my player is moving in unity 2d? 1 Answer

How can I make 2D movement less jerky on a controller, with velocity and such? 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