Hi, i currently have a my character which i can move with the left analogue stick perfectly fine, i now want to make it so that i can control which way the character faces using the right analogue stick. So i could be moving left with the left stick while aiming right with the right stick etc.
Here is my code currently:
[RequireComponent (typeof (PlayerController))]
public class Player : MonoBehaviour {
public float moveSpeed = 5;
public float rotateSpeed = 10;
PlayerController controller;
Camera viewCamera;
First you probably need to set up the new axes in the input manager, using the 4th and 5th joystick axes (set them up the same as horiz and vert)
Then you poll the Input much the same as you already have, and use Quaternion.LookRotation to rotate the GameObject
I realize this is 5 years old, but the internet is full of jack all and none of it is correct.
This is what anyone who reads this here and forward needs. Please use the new-ish unity input manager.
aim()
{
Vector2 aim = gamepad.rightStick.ReadValue();
Vector3 direction = new Vector3(aim.x, 0, aim.y); //if you’re 2d side scroller, you need to swap 2nd and 3rd value.
transform.rotation = Quaternion.LookRotation(direction);
}
apply the script to the character and they will rotate to your right joysticks direction.
Don’t just pick random threads from 2015 to respond to.
When you have a problem, start a new thread: it’s free and it is the forum rules.
It sounds like you just have a typo. You can fix your own typos. Here is how:
Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.
The complete error message contains everything you need to know to fix the error yourself.
The important parts of the error message are:
the description of the error itself (google this; you are NEVER the first one!)
the file it occurred in (critical!)
the line number and character position (the two numbers in parentheses)
also possibly useful is the stack trace (all the lines of text in the lower console window)
Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.
All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.
If you have an actual question rather than just stumbly fingers, here is how to report your problem productively in the Unity3D forums: