Quantcast
Channel: Questions in topic: "follow"
Viewing all articles
Browse latest Browse all 536

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

$
0
0
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(); } }

Viewing all articles
Browse latest Browse all 536

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>