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 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.

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

No movement to negative z-axis. 1 Answer

advanced problem for me regarding transfering rotation from the gizmo to the object 0 Answers

Problem Rotating up vector of camera to mouse position on screen. 2 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