I’ve been trying to figure out how to make my pawn properly so that it does not do this. I’m mostly following tutorials so I tried using AddMovementInput but the pawn wouldn’t move, same thing as AddInputVector (I assume I might have missed out some things?). I did not save the code but there was one where the pawn would just face-plant into ground rather than moving. I don’t know how to post my code so I’ll just attach screenshot here.
I’ve also noticed that changing some stuff in the movementcomponent does not affect the pawn at all, should the pawn move using the movement component?
Anyways, I’d really appreciate it if anyone could help!
I think the reason why AddMovementInput or AddInputVector did not work is because I had simulate physics on. I want to make a physics based movement so idek what to do at this point.
You’ll probably want to implement your own friction forces as well so you don’t accelerate infinitely. Generally takes the form of -F x Velocity to -F x Velocity²
void Tick(float dt)
{
Super::Tick(dt);
auto Comp = Cast<UPrimitiveComponent>(GetRootComponent());
FVector V = GetVelocity();
if (Comp && !V.IsNearlyZero())
{
Comp->AddForceAtLocation(-Friction * V.Size() * V.GetSafeNormal(), GetActorLocation());
}
}
Make sure the root component is the one that simulates physics.
Otherwise you need to apply forces to the appropriate component.
The mass of the object can play a huge factor, multiply your forces by that amount. A simple 1x1x1 cube defaults to 177kg in mass by the engine. So you need a force of like 10000 if you want to see something move.
Alternatively you can use the “bAccelChange” parameter to ignore mass, and work with more reasonable values, but this parameter is not available in every function.
If you use gravity you’ll have a very strong drag force against you when on ground (imagine pushing a 177kg container on the floor). You’ll probably want to code some mechanism to work around that.
Finally, you don’t really need to code friction because engine provides linear/angular damping properties in the Physics section, which do basically the same.
PhysicsPawn.cpp (5.5 KB) PhysicsPawn.h (1.8 KB)
I’m gonna stop working for today but this is my code so far, I tried a few changes before saving so it might not look like what you expect + i’m a beginnner
So your speed force is 1 and your friction force is 10000 that’s a first problem. Remove friction you don’t really need it, you can play around with builtin damping parameters later on.
Second, code in add force is wrong I wonder how it even compiles :
Sorry for the late reply, been really sick for the past few days. So it was a syntax error. How can I make it so that it moves normally without having to be mid air? Like make it start moving on directional input.
Turns out that I was not applying enough force. I added * 5 as an example to see if anything would change and it’s moving now even when it’s not mid air.