Hello, I’m trying to code a 2d player control for a retro style platformer.
I’m pretty sure i’m doing something wrong due my lack of knowledge.
At the moment I’ve a player control that “works” but i’ve some minor odd behaviours and i’m pretty sure i’ve made a mess with the control logic.
I’ve derived UMovementComponent to have the possibility to use **SafeMoveUpdatedComponent ** method to avoid to check collisions on my own.
My blueprint sets the Velocity accordingly with the keys pressed/released (InputActions)
void UBarrellMotion::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
FRotator no_rot;
FHitResult hit;
UE_LOG(LogTemp, Warning, TEXT("%f %f %f"), Velocity.X, Velocity.Y, Velocity.Z);
FVector _v = Velocity;
if (wallfaced){
_v.X = 0;
}
this->SafeMoveUpdatedComponent(_v, no_rot, true, hit);
if (hit.Normal.Z == 1){
this->Velocity.Z = 0;
grounded = true;
}
else{
this->Velocity.Z -= gravity;
}
if (abs(hit.Normal.X) == 1){
wallfaced = true;
}
else{
wallfaced = false;
}
}
Now, the problems are:
- Is this a good way to do that? Am I reinventing the wheel? I want to code my own character control to be sure to have a experience as close as possible to the old platformer games
- The wallfaced bool is used to understand when i’m facing against an horizontal wall. If i don’t put to zero the velocity on the X i’ve a “friction” behaviour (i’m pretty sure I don’t have any kind of physics, masses, frictions or stuff like that. I something of those is involved i don’t know where to look to disable it)
- At the moment i’ve i’m against a wall, keeping the right/left key pressed, and i try to jump, the jump itself is shorter than a regular jump without being against a wall (and pressing the key). Is that an effect of the point 2?