• 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 aliklorenz · May 02, 2018 at 03:29 AM · rotationjoystickmouseposition2.5daim

Rotate player to aim on one axis (Z-axis) towards mouse position/joystick - 2.5D (3D)

I am fairly new to Unity and I am trying to make a game similar to Super Smash Bros. So a 2.5D type of game where plays only move horizontally. I want my players to be spheres with a smaller sphere that rotates 360 degrees around them to aim. Here is an example of what I mean: alt text
Not the best angle, but what I am trying to do is have the green sphere rotate 360 degrees around the other sphere on one axis. I am trying to figure out the best way to do this/ a script to do it. I sort of had a script that would rotate the sphere towards the mouse, but it was glitchy and made the player movement not work well. Then I thought it may be easier to rig up a bone in blender from the center of the sphere out to the smaller "hand" sphere so I could just rotate the bone. I am still having trouble figuring out how to do this/ what the best way to do it is. Like I mentioned above, I want this resemble super smash bros, so there will be multiple people playing at a time so I also want to handle rotating the "hand" with a joystick as well. Any recommendations would be greatly appreciated!
Here is my movement script right now without any rotation code:
`

public class PlayerMovement : MonoBehaviour
{

 public float speed = 10.0F;
 public float jumpSpeed = 13.0F;
 public float gravity = 25.0F;
 public float amount = 10;

 private Vector3 moveDirection = Vector3.zero;
 private CharacterController controller;
 private int jumpCount;
 


 // Use this for initialization
 void Start()
 {
     controller = GetComponent<CharacterController>();
     rb = GetComponent<Rigidbody>();
 }

 // Update is called once per frame
 void Update()
 {

     if (Input.GetButton("Fire1"))
     {
         rb.AddForce(Vector3.back * amount);
         print("clicked");
     }

     if (controller.isGrounded)
     {
         moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
         moveDirection = transform.TransformDirection(moveDirection);
         moveDirection *= speed;
         jumpCount = 2;
         if (Input.GetButtonDown("Jump"))
         {
             jumpCount -= 1;
             moveDirection.y = jumpSpeed;
         }
     }

     else
     {
         if (Input.GetButtonDown("Jump") && jumpCount > 0)
         {
             jumpCount -= 1;
             moveDirection.y = jumpSpeed;
         } 
         moveDirection.x = Input.GetAxis("Horizontal") * speed;
     }

     moveDirection.y -= gravity * Time.deltaTime;
     controller.Move(moveDirection * Time.deltaTime);



 }

}

question.png (165.1 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

115 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

Related Questions

Point an arrow at the mouse position, 2.5D 1 Answer

How to get 360 directions from [joystick/mouse] instead of 8? 1 Answer

Rotate Locally Player Towards Joystick/Axis Input 1 Answer

Getting the face direction 2 Answers

Make a Player Model Rotate towards Mouse Location 3 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