if the AboveArrow is attacked to the root component, why are you setting its rotation in addition to setting the gravity, ALL SceneComponents that are attached to the RootComponent will be rotated based on the Gravity.
you are also setting the Relative Rotation of the SceneComponent to be based on a World PoV Normal vector (look at what these changes are actually doing: for the AboveArrow in Rendering→HiddenInGame = false)
- if the actor currently has its gravity set to the default of -Z, then the AboveArrow will have an orientation pointing exactly Up
- if the actor then has its gravity set to a
<1/sqrt(2),1/sqrt(2),0> ( ~.707) gravity the Up Vector SHOULD be <-1/sqrt(2), -1/sqrt(2), 0>, which is what the world ForwardVector of the AboveArrow would be just before you set its RelativeRotation
- the new world ForwardVector of the AboveArrow would close to (floating point approximation not withstanding)
< -sqrt(2),-sqrt(2),0> (~1.414 ) which would be pointing to the left (because a zero-rotator would be pointing forward, and the windings of a unit circle in trig goes counter clockwise)
the current UpVector of an actor for the purpose of your line trace can be obtained in a couple ways not requiring you to hold an ArrowComponent (keep it for editor visualization but don’t rotate it, and you don’t need to actually reference it, and probably mark it as EditorOnly)
- Negate(GetGravityDirection()) from MovementComponent
GetCapsuleComponent→GetUpVector() // in most cases the CapsuleComponent is the RootComponent, so therefore its transform is the Actor's Transform
keep in mind that the UpVector is defined in World space that is why you don’t need to convert it into world space to do your line trace.
try drawing your vectors using DebugDrawLine. I have a strong feeling that your gravity is pointing in a different direction then you believe
// these do not need to be actual variables, labels are for text.
// this is directly doable in Blueprints
Tick()
{
VectorA = GetActorLocation() + <100,100,100>
VectorB = VectorA + (100.0f * GetGravityDirection())
DrawDebugLine ( VectorA, VectorB, Yellow)
VectorC = VectorA + (100.0f * GetCapsuleComponent()→GetUpVector())
DrawDebugLine ( VectorA, VectorC, Pink)
//and for sanity sake add this too see actual gravity
VectorD = VectorA + (100.0f * FVector::DownVector) // <0,0,-1>
DrawDebugLine(VectorA, VectorD, Green)
}
I have a strong feeling that it looks like it is sliding to the side because your GravityVector is not oriented properly.
are you using the Box2D physics, or are you using the 3D physics system? the Box2D physics system might be overriding your character’s orientation to be alternative to the Gravity based UpVector, and therefore it looks like you are sliding to the side.