x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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...

Product Version: Not Selected
Tags:
more ▼

asked May 03 '14 at 08:20 AM in Blueprint Scripting

avatar image

TheOnlyDoubleF
81 7 7 11

avatar image Sublimation Mar 07 '17 at 11:57 PM

Does anyone know how to make this work on third person in a way that will change direction in between two anim montages?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

7 answers: sort voted first

Hey Franck Fitrzyl,

Here's one possible solution, I'll include a short primer for how this is setup:

  • Using Third Person Blueprint Template as the base

  • Modified ProjectSettings > Input to have FaceNorth and FaceEast events for Y-axis and X-axis of the Right Gamepad Stick, respectively

  • After removing some of the old Axis Events from the below list, you'll want to delete their Events from the Graph (if you compile after removing them from the settings list, they'll be tagged yellow for you by the editor so you can just delete them)

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:

TwinStickInputs

  • In the MyCharacter Blueprint, changed spring arm component to not use controller view rotation and adjusted the length of the spring arm to 700 and the rotation of the spring arm to (0, -90, 0) (this step keeps the camera in a fixed, top-down position)

  • In the MyCharacter Blueprint Defaults, search for Orient Rotation to Movement and make sure it is un-checked.

I think that's the only other modifications I made outside of this setup in the Eventgraph in MyCharacter:

TwinStickSetup

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!

-Steve

more ▼

answered May 09 '14 at 11:16 PM

avatar image

Steve Allison STAFF
4.3k 123 58 209

avatar image mindfane May 10 '14 at 01:45 AM

I was trying to adapt this to the sidescroller template. However I wanted the character to retain his last rotation when the stick is released instead of restting to default rotation.

And since we are actually rotating the Mesh, does it affect where the character will fire his gun?

avatar image Steve Allison STAFF May 11 '14 at 05:20 PM

To keep the last rotation when the stick is released, you would just want to put in a check that uses the last rotation when it detects the stick is reset back to it's default position. I can provide a work around if you hit a wall trying to implement that functionality.

Also, you can use the mesh's rotation to calculate the vector in which you wish to fire your gun.

avatar image mindfane May 12 '14 at 02:46 AM

Thanks.

I got it working in a different way. Mine was a side scroller so I did not have to worry about the analogue value of right stick. So all I did was setup a boolean variable FacingRight and switched it when the stick value changed signs. I know this wont work for a 3D game.

avatar image TheOnlyDoubleF May 10 '14 at 07:42 AM

I've reproduced exactly the same way you explained it and my character do not even rotate

avatar image Steve Allison STAFF May 11 '14 at 05:55 PM

Hey Frank Fitrzyl,

I amended a couple of things in my steps list and ran through it again, there were a couple of items I omitted and my 2nd screenshot was missing a pin connection. The key item I added was to make sure to uncheck the Orient Rotation to Movement option from MyCharacter's defaults. Try out these steps again and see if that works for you.

avatar image meterpooney Apr 08 '17 at 12:38 AM

Just wanted to say thanks! This perfectly solved my problem!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered May 03 '14 at 01:20 PM

avatar image

mindfane
3.4k 154 52 271

avatar image TheOnlyDoubleF May 09 '14 at 07:02 AM

I don't find anyhing that refers to the stick orientation in the blueprint function, or I do not use the well

avatar image mindfane May 09 '14 at 03:37 PM

Sorry, I could not find the original code. Anyway it was pure unrelascript and may not be applicable here.

So try this: Bind an AxisMapping on right anologue stick to 'CharacterFacing'. Now you can create an event node Character Facing in blueprint. It will have an input value ranging from 1 to -1. You can use that to decide the rotation of your character. But you should not use the value right away. YOu only need the sign of the value. IF the sign chages, then you set the rotation of charcter (but dont feed it into Move Input. or it will rotate for ever).

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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... alt text

capture.png (50.2 kB)
more ▼

answered May 09 '14 at 06:45 PM

avatar image

Dave4723
329 10 16 33

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Ok, I am not sure if this is what you want, but here is a crude implementation that does the follwoing:

  • Use left analogue stick to control the charcter (move left and move right). Will not change charcter's orientation

  • Use right analogue stick to decide the facing direction. ie where the charcter looks at.

  • This based on the side-scroller template from unreal engine. I added two new Action mappings (FaceRight to AnalogueRightStkRight and FaceLeft to ANalogueRightStkLeft)

alt text

right_anlg_stk.jpg (165.1 kB)
more ▼

answered May 09 '14 at 04:49 PM

avatar image

mindfane
3.4k 154 52 271

avatar image TheOnlyDoubleF May 09 '14 at 06:31 PM

I've tried that, It's not really working well but it's may be kind of a beginning. I can only rotate on the left, and I can do it only one time... and of course, because of the Yaw value that we've added in the Make Rot node, it rotate -90°, so I also have to find a way to get my stick orientation to rotate the character smoothly.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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 alt text

capture.png (141.4 kB)
more ▼

answered May 09 '14 at 10:03 PM

avatar image

TheOnlyDoubleF
81 7 7 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

that should be managable...

it sounds like you need a static vector and a threshold...

so

  1. Create a vector-variable which holds your gamepad-vector

  2. check the Axis values delivered by your events for it's amplitude (how big or small is getting the value? from -1 to 1 or something else?)

  3. decide upon this how great your threshold value should be

  4. update your vector value only if it's greater than your threshold

alt text 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

capture.png (160.3 kB)
more ▼

answered May 10 '14 at 05:55 AM

avatar image

Dave4723
329 10 16 33

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Jul 19 '14 at 04:48 PM

avatar image

tebruno99
91 5 8 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question