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 kofficoffee · Sep 13, 2018 at 06:33 PM · 2d gamerigidbody2dvelocitytopdownz-axis

How do I make my character move on the Z axis on 2d rigidbody?

Im using rigidbody2ds velocity feature for movement and i need to move my character on the Z axis, problem is I cant figure out how to enable the Z axis for rigidbody 2d. It's a topdown roguelike sprite game with movement similar to binding of isaac. This is my current script.

 using UnityEngine;
 
 /// <summary>
 /// Player controller and behavior
 /// </summary>
 public class PlayerScript : MonoBehaviour
 {
     /// <summary>
     /// 1 - The speed of the ship
     /// </summary>
     public Vector3 speed = new Vector3(50, 50, 50);
 
     // 2 - Store the movement and the component
     private Vector3 movement;
     private Rigidbody2D rigidbodyComponent;
 
     void Update()
     {
         // 3 - Retrieve axis information
         float inputX = Input.GetAxis("Horizontal");
         float inputZ = Input.GetAxis("Vertical");
         float inputY = Input.GetAxis("Y");
 
         // 4 - Movement per direction
         movement = new Vector3(
           speed.x * inputX,
           speed.y * inputY,
           speed.z * inputZ);
 
         // ...
 
         // 5 - Shooting
         bool shoot = Input.GetButtonDown("ArrowRight");
         bool shootup = Input.GetButtonDown("ArrowUp");
         bool shootdown = Input.GetButtonDown("ArrowDown");
         bool shootleft = Input.GetButtonDown("ArrowLeft");
         // Careful: For Mac users, ctrl + arrow is a bad idea
 
         if (shootdown)
         {
             WeaponScriptDown weaponup = GetComponent<WeaponScriptDown>();
             if (weaponup != null)
             {
                 // false because the player is not an enemy
                 weaponup.Attack(false);
             }
         }
         if (shootleft)
         {
             WeaponScriptLeft weaponup = GetComponent<WeaponScriptLeft>();
             if (weaponup != null)
             {
                 // false because the player is not an enemy
                 weaponup.Attack(false);
             }
         }
         if (shootup)
         {
             WeaponScriptUp weaponup = GetComponent<WeaponScriptUp>();
             if (weaponup != null)
             {
                 // false because the player is not an enemy
                 weaponup.Attack(false);
             }
         }
         if (shoot)
         {
             WeaponScript weapon = GetComponent<WeaponScript>();
             if (weapon != null)
             {
                 // false because the player is not an enemy
                 weapon.Attack(false);
             }
         }
 
         // ...
 
     }
 
 
     void FixedUpdate()
     {
         // 5 - Get the component and store the reference
         if (rigidbodyComponent == null) rigidbodyComponent = GetComponent<Rigidbody2D>();
 
         // 6 - Move the game object
         rigidbodyComponent.velocity = movement;
 
         // 7 - Z axis in rigidbody
         
     }
 }

Comment
Add comment · Show 1
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 tormentoarmagedoom · Sep 14, 2018 at 08:43 AM 0
Share

Good day.

This script was done by you? How is posible you dont know how to do it if you wrote al lthis script?

If the script is not yours, and you just copy paste it, you should go learn more about movement, vectors, addforce and velocity,

Bye!

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

164 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

Related Questions

How to stop cube from sliding (rg2d.velocity) 1 Answer

Acceleration/Deceleration on a Rigidbody2D 0 Answers

Terminal velocity on x and y axis is higher than normal when force is applied to both axis simultaneously. 0 Answers

How to reverse a reading of degrees 2 Answers

No overload for method. (Question) 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