A Turning Problem

Working on a ski game and turning is just not wanting to work.

I’m moving the character forward with this:

UCapsuleComponent* CapComp = GetCapsuleComponent();

FVector ForwardDir = GetActorForwardVector();

FVector ImpulseVect = ForwardDir * 50;

CapComp->AddImpulse(ImpulseVect, NAME_None, true);

The current turn code is this:

float TurnDirection = Value.Get();

UCapsuleComponent* CapComp = GetCapsuleComponent();
FRotator CurRot = CapComp->GetRelativeRotation();
FRotator NewRot = CurRot + FRotator(0.f, 0.f, TurnDirection * 10);
CapComp->SetRelativeRotation(NewRot);

I’ve tried everything. If I try AddControllerYawInput, I can get the model to rotated and turn but the movement direction doesn’t carry over - e.g. the model turns but continues in the same direction. Everything else, whether I use ActorRel or Capsule results in the gif above.

Any suggestions, insight or help would be greatly appreciated.

Bump

hi @LockeKosta

Is your capsule the root? im guessing so as you are using it to add impulse.

Another thing to try is Set Actor Relative Rotation? see if that works, maybe your forward vector isnt being updated when you rotate the capsule

Impulse is intended for one time bursts like explosions, use AddForce or play around with velocity values to have smooth motion changes over time.

Also you might not get the desired results if you i.e rotate a capsule but it’s not the actor’s root component and then try to use actor’s rotation to determine the new direction.

It is the root, here’s a picture of the character blueprint:

And SetActorRelativeRotation produces the same result.

Impulse is the effect I’m looking for, e.g. pushing off with ski poles. AddForce actually doesn’t work and idk why when Add Impulse does, but either way there needs to be drag/friction to a degree so a constantly application isn’t really what I’m looking for.

Regardless, doesn’t change my turning issue. The capsule is the root and I’ve tried all the “set actor” functions I can find only to wind up with the same results.

AddForce takes into account DeltaTime so you typically need far greater values with it anyway. I can understand where you’re coming from though I’d wager that Impulse is more made with explosions in mind rather than ski physics.

Try debugging whether if you are actually getting the correct direction i.e always get the direction before adding the impulse instead of using a cached value.

I’d recommend using character movement component and setting velocity values from there instead of trying to play with forces immediately. It might be more suitable for the game to use some custom physics calculations for adding the appropriate speed rather than using the in-built physics system.

I don’t think core system functions are designed with such singular purposes in mind, otherwise why call it AddImpulse and not AddExplosionForce?

I already have it set up to where there’s no other code involved. The impulse is applied on pressing W while the turn is set to A and D. Neither are in event tick or anything like that so there’s nothing that could be overriding the direction code-wise.

It’s funny that your recommendation goes against 5-6 other sources I’ve seen that have said the exact opposite - to never manually mess with setting velocity values. Regardless, the impulse is what I’m looking for. That’s working as intended. I think it’s a little soon to immediately throw up hands and jump to manually having to create all of the physics.

I’m fairly new to Unreal but I come from an extensive Unity background. I couldn’t tell you the amount of times people have told me something had to be done a certain way with multiple scripts only for me to figure out how to do the same thing better with a few dozen lines.

I find it hard to believe there’s no answer here other than handling it all completely differently and having to code friction by hand.

ok so once the forward vector is impulsed or add force, thats the direction it will go, so what i suggest is look at using physics on the skis, kinda like wheels on a car. its essenstially a mode of transport. so look at how the wheels turn in an unreal car project and maybe use physics objects (kinda like ski pushes with polls and then gravity) to move

so in essence have some rear physics “wheels” not meshes. at the rear of the player skis, and then midpoint on the skis have “Front wheels” that turn, again not actual meshes or hidden ones if needs be.

really do suggest you look at a vehicle setup as its a similar logic only difference is no engine and you use pole pushes

Maybe my understanding of impulse and force in Unreal is colored by how I’ve seen it work in Unity.

So you’re saying Impulse isn’t really adding to the character/object in a way that adjusts/manipulates its velocity. Instead it’s treated more like a separate physics calculation entirely?

My thought process is more that pushing off with ski poles would essentially be a singular application of force, i.e. an impulse.

I still don’t understand what this has to do with my main issue of turning/rotation though. Even if I remove the impulse code entirely, the same issue occurs. The character isn’t rotating, they’re moving side to side. Even bouncing with enough change made. Despite my attempts to change the rotation in ways everyone and their mother swears works.

impulse works by adding a directional impulse, but because theres no friction between your character and the ground as it were, it will move like on ice as there is nothing to tell it otherwise.

I used the same type of thing on my side game have a look. the ship travels onwards until i apply an opposite or different directional force

Sounds like I need to handle velocity and direction almost completely separate. I did this:

   float TurnDirection = Value.Get<float>();
      UCapsuleComponent* CapComp = GetCapsuleComponent();
   FVector CurVel = GetVelocity();
   float howFast = CurVel.Size();
   AddControllerYawInput(TurnDirection);
   FVector ForDir = GetActorForwardVector();
   FVector NewVel = ForDir * howFast;


   CapComp->SetPhysicsLinearVelocity(NewVel, false, NAME_None);

It kind of works, of course the problem being that speed is being maintained while turning which is almost kinda the opposite of what needs to happen. I’m really unsure if this is the right direction to go down now or if I need to completely rethink how the character moves entirely.

maybe you can implement some sort of braking over time whilst turning?

At that point I would be handling the physics all manually anyway and would prob be better off just adjusting char walk speed and manually creating all of the physics.

I did think that myself after i hit the reply button.

I still think treating the skis like some sort of vehicle movement instead of add impulse or force. Hopefully that should be too difficult maybe check this out:

How to Slide/Glide/Skate/Ski in Unreal Engine UE5 UE4 Tutorial - YouTube

Unreal Snowboarding System - YouTube

I promise there’s not a youtube video out there on this subject that I haven’t already seen. The first one is using a plugin and blueprinting, both which come with their own issues. The other one looks like its ripping code from another project for the core of its movement.

I might check out going the vehicle movement route or something I guess.

Still find it crazy that no one can seem to understand why the character won’t turn properly with rotation code.

hes using his own code i believe from another tutorial for the skateboard, not sure. but i dont say copy, i say learn the principles and see what they do different then do your own thing.

i understand why it dont turn as there is no physics to tell it there is turning. like a spaceship on no atmosphere in space. add an impulse and no matter what way you face the impulse will continue in the direction it was directed. there is no friction in space (well nearly none) so theres nothing to make the direction of travel change.

This is how impulse works here.

Therefore you need to add physics based detection on your skis and use the engines built in physics system to account for that. whence the vehicle tutorials are most appropriate as they deal with wheels turning, which uses friction. It cant be difficult to implement surely?

i understand why it dont turn as there is no physics to tell it there is turning.

That doesn’t make any sense. If I add 10 to the Z rotation in the scene, it turns. That’s all the code is saying to do. Physics isn’t part of it. My use of impulse and changing forward direction while moving is ancillary. The character is sliding left and right when the Z rotation is being changed. That’s not how that’s supposed to work.

The direction of travel change was not my question to begin with.

My question has been, why is this:

UCapsuleComponent* CapComp = GetCapsuleComponent();
FRotator CurRot = CapComp->GetRelativeRotation();
FRotator NewRot = CurRot + FRotator(0.f, 0.f, TurnDirection * 10);
CapComp->SetRelativeRotation(NewRot);

Causing the character to slide and/or hop from side to side instead of turn/rotate. Ultimately has nothing to do with impulse and physics.

thats what you originally asked, thats why i posted what i did. all the rotation of the capsule does its rotate the object but doesnt tell it the driection of travel

Working on a ski game and turning is just not wanting to work.

I was merely explaining other things I’ve tried. Literally the only way I’ve gotten any object to turn at all is using AddControllerYawInput, which seems rather absurd. From the get-go I’ve wanted to know why this:

float TurnDirection = Value.Get();

UCapsuleComponent* CapComp = GetCapsuleComponent();
FRotator CurRot = CapComp->GetRelativeRotation();
FRotator NewRot = CurRot + FRotator(0.f, 0.f, TurnDirection * 10);
CapComp->SetRelativeRotation(NewRot);

Causes the character to do the electric slide instead of rotating along the Z-axis. With that code alone and nothing else, you get the result in the gif. (Actually it’d hop instead because of the * 10 but still basically same result.)