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();
}
}
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.
I did add tags, but I can agree about the title, thanks :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612222836im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Getting Over It Like Physics 0 Answers
2D - Object follow cursor on X-axis. 0 Answers
Problem with Prefab - Following cursor 0 Answers
Is there joint physics example asset? 0 Answers