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
-1
Question by TheFatherOfGames · Feb 06, 2020 at 02:45 PM · physics2dcursorfollowjointscontrol

Is it possible to make a cursor using right stick axis of an xbox controller?

I have 2 players one controlled by the mouse and keyboard and another one who i am trying to make move and just generally be controlled by an xbox controller. I need some kind of script that would make the second player's hand (attached with a hinge joint) follow a cursor controlled by the right stick of the controller (i already made the cursor(texture)) . Any ideas? I have searched a lot and this problem is giving me a headache.

here"s the script for the player's movement

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Rewired;
 
 public class MoveOther : MonoBehaviour
 {
   
 
 
 
     
     public ParticleSystem dust;
     public ParticleSystem dust1;
     public Rigidbody2D hip;
     public Limb handR;
     public Limb handL;
     public Limb legR;
     public Limb legL;
     Camera cam;
     public JumpOnce jump;
     public JumpOnce jump2;
     //public string horizontalCtrl = "Horizontal_P1";
     //public string jumpButton = "Jump_P1";
     
 
     public float hipForce = 500;
     public float moveSpeed = 500;
     public float jumpForce = 500;
     
     // public int JumpCharge = 1;
     int frameIndex = 0;
     int dir = 1;
     
     // public void SetGrounded(bool value) {
     //     if(value) {
     //         if(hip.velocity.y > 0){
     //            JumpCharge = 1;
     //         }
             
     //     }
     // }
 
     public int playerID = 1;
     private Player player;
     
     
     private void Start()
     {
         player = ReInput.players.GetPlayer(playerID);
         
     }
   
     
     
     void Update()
     {
         RotateTo(hip, 0, hipForce);
 
         var direction = player.GetAxis("Horizontal_P2");
         
         
         if(Mathf.Abs(direction) > 0) {
             hip.AddForce(moveSpeed * direction * Vector2.right);
             if(frameIndex > 10) {
                 frameIndex = 0;
                 dir *= -1;
             }
             legL.setPosition(Vector2.right * 10 * dir + Vector2.down * 7);
             legR.setPosition(-Vector2.right * 10 * dir + Vector2.down * 7);
             frameIndex++;
 
             if(jump.grounded == 1){
                 CreateDust();
             }
          
             
         }
 
         if(player.GetButtonDown("Jump_P2") && jump.grounded > 0) 
         {
 
             
                
             hip.velocity = Vector2.zero;
             hip.AddForce(jumpForce * Vector2.up, ForceMode2D.Impulse);
             //JumpCharge--;
             CreateDust();
                
         }
 
 
         
 
         
   
     }
 
    
     
 
 
     void RotateTo(Rigidbody2D rigidbody, float angle, float force) {
         
         angle = Mathf.DeltaAngle(transform.eulerAngles.z, angle);
 
         var x = angle > 0 ? 1 : -1;
         angle = Mathf.Abs(angle * .1f);
         if (angle > 2) {
             angle = 2;
 
         }
         angle *= .5f;
         angle *= (1 + angle);
 
         rigidbody.AddTorque(angle * force * x);
     }
 
 
     void CreateDust() {
         dust.Play();
         dust1.Play();
     }
 }
 
 
 




Comment
Add comment · Show 2
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 · Feb 06, 2020 at 03:54 PM 0
Share

Hello.

This post needs a specyfic title about its content. All post can be titles "How i do..." thats the reason of Unity answers. So please, write a atitle and tags about your problem.

avatar image TheFatherOfGames tormentoarmagedoom · Feb 06, 2020 at 04:24 PM 0
Share

I did add tags, but I can agree about the title, thanks :)

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

197 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Getting Over It Like Physics 0 Answers

2D - Object follow cursor on X-axis. 0 Answers

Why Hinge Joint 2d easily goes out of set angle limit? Can I lock an angle so the rigidbody not rotates out of an angle? 0 Answers

Problem with Prefab - Following cursor 0 Answers

Is there joint physics example asset? 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