void ASpidi_Controller::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
TickTime = DeltaTime;
/Determine if the character is moving by getting it’s speed./
Speed = FVector(GetVelocity().X, GetVelocity().Y, 0.0f).Size();
//SweepFloor();
//TraceForFloor();
//SpiderSense();
// Perform the raycast downward from the spider's current position
FVector StartLocation = GetActorLocation();
FVector EndLocation = StartLocation - FVector(0.f, 0.f, 150.f); // Move down by 150 units
FHitResult HitResult;
// Ignore self by creating a trace params object and setting the actor to ignore
FCollisionQueryParams TraceParams;
TraceParams.AddIgnoredActor(this);
// Perform the raycast
if (GetWorld()->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECC_Visibility, TraceParams))
{
// Set the spider's position above the hit point
FVector NewLocation = HitResult.ImpactPoint + FVector(0.f, 0.f, 100.f);
SetActorLocation(NewLocation);
// For visualization purposes
DrawDebugLine(GetWorld(), StartLocation, EndLocation, FColor::Green, false, 0.1f, 0, 1.f);
DrawDebugSphere(GetWorld(), HitResult.ImpactPoint, 10.f, 8, FColor::Red, false, 0.1f);
}
}
This tick function perform a line trace and set the actor with the offset of Hitlocation.Z + 150.f. The problem is, when i start to move the movement speed increase gradually and keep increasing very slowly and after i stopped input movement it keep moving.