How would I get my character rotation to match the gamepad stick orientation?
Hi, I'm making a shoot'em up in in the style of Beat Hazard. I've set up my character movement on my Xbox360 Gamepad Left stick and his rotation on my right stick.
The problem is, if I hold my right stick for example on the right, my character rotate clockwise endlessly. I just want my character to point in my stick's direction.
Right now, My PlayerController BP is set like that : http://gyazo.com/01aabe3c259863603ee70fa7a395250f
"Rotate" is for rotating on the left and the right and "Look up" is for rotating toward top and bot. It's probably a simply thing but i've already lost a work day on it so...
Hey Franck Fitrzyl,
Here's one possible solution, I'll include a short primer for how this is setup:
Edit: Here's what all of my Axis events look like, just to be clear on how they're setup and what I removed from the Template:
I think that's the only other modifications I made outside of this setup in the Eventgraph in MyCharacter:
This setup only rotates the Mesh (and not the capsule component, which is the root of the whole blueprint). Basically, the axis values make an input (like was being done in some of the other screenshots in this example), then the inputs are made into a 2-d vector (Z = 0). We then take the Actor's location and add this new vector to get a target location to look at, which is fed into a Find Look at Rotation node (super handy node, btw) and we set the Mesh's world rotation to that new rotation.
If you have any questions about this setup, please let us know!
Hope this helps out!
I had done a similar thing in UDK about a year ago. But unfortunately I dont have the code with me. But I think I can give a basic idea of how I did it.
So in my UDK project which was a side scroller, the player controlled a ship with left and right sticks. The left stick controlled the ships height (UP-DOWN) and moved it to the right or left. The right stick controlled whcih direction the ship was facing and thus where the ship would fire bullets.
I have a float called facingDirection, which is 1 when ship is facing towards right hand side and -1 when facing towards the left hand side. Then I switched between 1 and -1 based on the right analog stick horizontal axis value. Multiply this value with the normalized vector that points to the right hand direction (got from the camera). Convert this to a Rotator and set as the Rotation of the Actor.
PS: I will see if I can find the original code and post it here if I find it.
You must also check FaceRotation() function in APawn
i don't have a controller so i could not verify this but with the gampad input events you get an axis...
so i would use a 2dvector for your stick orientation... on "gamepad right x" you set the vectors xcomponent and on "gamepad right y" you set the vectors y component... (these events have an axis value)
then you can use this vector to set your pawn's orientation...
Ok, I am not sure if this is what you want, but here is a crude implementation that does the follwoing:
So,it's half working as expected now thanks to your advices.
When I rotate my Gamepad right stick in any direction, my character rotate but... it's reversed relative to my stick orientation.
Secondly, when I release the stick, the character goes back to his initial orientation. Of course, I'd like to keep his rotation even if I release the stick. Any idea ?
Here's what I've got now
answered May 09 '14 at 10:03 PM
that should be managable...
it sounds like you need a static vector and a threshold...
when your orientation is of by 180 degree then you have to flip both x and y by multiplying with -1 another thing i did not include here is, when your axisvalues reach from -1 to 1 you have to check if the absolute value is greater than your threshold... othervise it would only work in the positive half
another thing is that i dont know how exacly the vector rotation thing works... so maybe there should be some changes, too. What i described so far gives you a vector which will always point in your last gamepad direction...
good luck and tell if it worked or if you need some more help
This is how I've chosen to do this. It seems to be working pretty well. Adjust the branch conditions to control the "dead" spot.
answered Jul 19 '14 at 04:48 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here