my question is rather simple although I must admit that it’s answer has been escaping me from days. As a matter of fact I got so frustrated that I even built up the guts to post my first question here - I have no idea why I didn’t do it before
so, here goes:
I rotate my actor (actually mmy controller, and the actor follows along) like in the first BP. 90 on the Z scale for left, -90 for right
I move it like in the second BP - by adding an offset to the Y axis. A few positive units get me a left strafe, a few negative units get me a right strafe.
It all works fine until the first rotation is executed. Then X and Y are all jumbled up together and my strafe becomes a leap forward or backwards and so on.
My question is - how do I modify my second Bp to take account of the rotation?
P.S. What I’ve tried and didn’t work:
the over-complicated way - make some sort of compass and get the actor direction (like south, east, north and so on) and make a huge Switch based on the result and make the turns based on that…this failed horribly
the apparently easier way (got it from an answer from this site, TBH) - get actor’s right vector, multiply it by offset (or minus offset), add it to get actor location and set actor location of the result. That sort of works, but I dropped it since I seem to get a different result each time it’s executed (I mean my actor never gets offseted with the same number of units. Only the methods in the first BP produces perfect results, but I need to make it also mind rotation)
maybe there is someone who has been using UE longer than I did who might be able to help me out.
So, you have a move-vector in “local space” and an actor/control rotation. Why don’t you just use the actor or control rotation (maybe set pitch to zero first) to call “RotateVector” on the move-vector and use the result as the final, global move direction?
Thank you very much for your quick answer MaxPower42, although I’m not sure I understand all of it (i got…some of it as I literally started with UE this year (around the 1st or 2nd of Jan)
The way I understood it, your problem is that your character’s move-direction isn’t properly adjusted to the direction he is facing. That means you already have a vector that defines the direction he should move to, it just needs to be adjusted. You say, roating the character works fine. So, all you really need to do is to rotate the move-vector by the character-rotation:
The first function (World) is what I had in mind, but as it turns out, there is an even easier way to do it with the function below. I don’t know what your input looks like, but of course you should multiply it with DeltaTime at some point.
If this doesn’t help, maybe you should explain exactly what kind of motion you want to create, how you deal with player input, and post an overview screenshot of your blueprint.
“The way I understood it, your problem is that your character’s move-direction isn’t properly adjusted to the direction he is facing. That means you already have a vector that defines the direction he should move to, it just needs to be adjusted.” - you understood perfectly! That’s exactly what I want - to learn how to do a rotation adjustment to a move command. Not only for this project, as it seems great knowledge for any type of game that gives the player the means to rotate and then go towards wherever the character is facing.
Unfortunately I’m at work right now, so while I can use the answer hub, I can’t actually test anything (UE4 doesn’t start at all on my Intel GMA ultrabook that I use in the office…I tried :(. Built projects work (with abismal FPS, of course), but the editor crashes after startup right during the viewport creation. High end SSD laptop, but still a business one. Works great for outlook, excel and the like though).
I’ll give it a shot in about 8hrs when I get home and come back if I get stuck.
Thank you once again and I honestly don’t know why I didn’t just ask on the answer hub earlier
Just got home from work. Since I abandoned the original project (it was a blueprint nightmare) I made a clone and worked on that one, dropping the rotation logic.
Here’s the working blueprint from it. It works great but only in straight lines. I DID try to adapt your solution 5 minutes ago but…my attempt was just to embarrassing to post here
I can’t thank you enough for your help, I basically gave up on rotations and tried to make the best of my project without it.
I think it would be best, if you could explain what kind of input and movement you really want to create. Is there an example of a game that has the same type of controls? It doesn’t sound like you want to make an average 1st or 3rd person kind of game. And I can’t really follow your blueprint approach. Maybe it’s better to start over, and I will try to help you finding the best approach. Giving up on rotation sounds a bit extreme
Of course, the result looks like a runner from 2010 (think Tempe Run 1 or Angry Gran Run) so I strived to make it better (and modern). I made a magnet and poweup system for it (works), made a 3 lane system for it (works, bujt only in straight lines - see my BP) and made another 3 lane system for it using set actor right vector (instead of set actor location) that doesn’t really work(each time it gives a different result, although it does mind rotation. I dropped this idea eventually).
All of this with the help of the Internets, as my one-week UE4 experience is hardly something to write home about.
I already started working on the assets for my straight-line endless runner (think Subway Surfers. I’m also using a curved shader) but…I I could ever get the corners going it would be great.
The BP I attached gets the lane variable on left/right swipe (bounded to an integer between 0 and 2, so there are only 3 possible lanes) and based on the new lane you’re supposed to be going to (the first checks if you actually may switch the lane) it lerps you to the new position based on an “lane_y” offset, which can either be 0 and a negative or positive value, based on your new lane position.
It’s not that complicated actually…except the part that the last node, the way I made it at least (to be read: adapted it from somewher else, as I’m not that proficient with UE4, no shame in that :)), doesn’t give a c*p about your rotation. It just addst the 0, negative or positive value to your Y and copies X and Z from your current location.
Ok, I finally understand what your lanes are all about. So, why don’t you just start by modifying the 3rd person template project exactly like in the tutorial video you posted? The turning behavior is fully covered there, as is the movement part (except the lanes). And when it comes to movement, I think your mistake is that you’re trying to do everything in the global reference frame, when it would make more sense to do it relative to the character or the direction that the game is currently treating as forward/run direction (more or less the same). In general, you always want to move your character along its own forward-vector and the lane-offset should always be rotated accordingly, so it matches the character’s current left/right-direction. Sorry, but I don’t know what else to say at the moment, that the guy in the tutorial couldn’t explain better… Maybe it would be a good idea to get more familiar with global and local transforms and reference frames first, and how to convert a vector between them through rotation.
“and the lane-offset should always be rotated accordingly” - this…I have no idea how to do that. And my math skills are close to nil - I did almost no math in highscholl (as my major was filology) and you don’t want to know how I passed my math-related uni exams While past my thirties now, I couldn’t rotate a vector on paper to save my life. I have lived a happy life so far with little to no math, and years of hobby-level programming taught me that the only math I need are enough arithmetics to count my change when I buy something and booleans - you can’t do s*t in programming without booleans
so, I’m pretty much back to square one. You are a pretty smart individual and figured out what I need to learn - as you put it - “the lane-offset should always be rotated accordingly” - but I don’t know how to do that.
The tutorials…I’ve done them in my first 2hrs of using UE. That’s actually how I learned the few bits that I know (I could probably make a simple tetris now because I know how to make a simple tetris. But i don’t want to make a teris as the world has already has seen enogh tetris games :). But the tutorial only get you so far - in this case - you get a straight endless runner with some corner turns based on rotating rhe controller +90 and -90 degrees - not really impressive.
oh, and the guy uses Add Movement Input tied to inputAxis for left/right which doesn’t really help me here as i tried to do something completely different. Which works, as long as i don’t rotate my pawn
Whatever destination point on the original (central) lane you would normally have to move your character towards it, you just need to rotate the offset-vector with the control-rotation of your character before adding it to that destination - just like the 3 nodes on the left in the picture I posted earlier. If you’d rather get a direction from the destination, it’s the same principle.
I’m not particularly good at math myself and completely self-taught, but without a basic understanding of vectors and orientations in 3D space, I’m afraid you won’t get very far in making a 3D game.
well I’ve succesfully made (some abismally looking I might add) bitmap-based games a long time ago when I was a child so I can think about X-Y operations on my own, including interpolation/smoothing. It’s the 3D space that beats me, even though I’ve been 3D modeling since like 15 years now (only hobby, used my models in a work-related short movie once, but other than that never went beyond things one does is his free time). I understand 3D space, I just can’t work out the math for it and I’m too old and lazy to start now
well…I just realized that we’re both debating over linear algebra (highschool stuff and usually repeated over the 1st year of most universities. Jesus…I guess I have to wait for like 15-16 more years for my one-year-old to grow up and break it apart in bits I can follow :))
I mean in 3D modelling you have the rotation of the object and the position. That’s usually relative to the world or to the parent object. I prefer to use the world in all cases for obvious reasons. Nothing less, nothing more. it worked fine for many years for me, including in animations (and I’m talking here rigid body collisions, soft collisions, particle emitters, even fluid simulation, as little of it as I’ve done because you can’t really do fluids on a GTX card or on a single CPU. I mean sure, you can leave it crunching overnight for a few frames but it’s just silly.
Well, it’s your choice, but this stuff really isn’t that complicated. I’m not suggesting you read a book about vector math or something… You can learn it all by doing. That’s what I did. If I wanted to compute a cross-product of two vectors manually, I would look up the math on wikipedia. If I wanted to manually rotate a vector component by component, I would have to look it up as well. The math isn’t important, because there are functions (in UE4 like in every other engine) for pretty much everything (see RotateVector). You just need to know what they are good for and have some “spatial understanding”, so you know what tools you can use to accomplish certain things. If you have rigged a 3D model, you know that every bone has a transform that is relative to its parent bone, just like vertices are being positioned in bone-space. So global and local reference frames shouldn’t really be all that new to you.