- Home /
Question by
SpaceBird_ · Mar 23, 2015 at 05:37 PM ·
2djavascriptaddforcedirectionjoysticks
How do you AddForce to a rigidbody2D in the direction of a joystick?
I've been trying to figure this out for a while now but I cant seem to get it right. I need to use two joysticks (the joysticks of an xbox controller) to AddForce in the direction they're facing. I set this up for the W, A, S, and D keys just to test if this is is what I want. This is the basics of what that script is:
var movePart1 : Rigidbody2D; // I need to move two things at once with the same
var movePart2 : Rigidbody2D; // joystick.
function Update () {
if (Input.GetButton("w")) {
MoveFoot1.AddForce (Vector3.up * 7);
}
if (Input.GetButton("a")) {
ETC...
So... How should I make this work with any angle / joystick input?
Comment