C
C
Cramon2021-09-25 21:35:51
unreal engine
Cramon, 2021-09-25 21:35:51

How to limit the movement axes of a physical object whose root object is SphereComponent?

There is a class PlayerBall inherited from Pawn with such components

//...

private:
//components
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
UStaticMeshComponent* BallBaseMesh;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
USphereComponent* BallHitSphere;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
USpringArmComponent* BallSpringArm;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
UCameraComponent* BallCamera;

//functions
void LeftRightMovement(float Value);

//...

Attachments are written in the class constructor

APlayerBall::APlayerBall()
{
 	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  PrimaryActorTick.bCanEverTick = true;

  BallHitSphere = CreateDefaultSubobject<USphereComponent>(TEXT("BallHitSphere"));
  RootComponent = BallHitSphere;

  BallBaseMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BallBaseMesh"));
  BallBaseMesh->SetupAttachment(RootComponent);

  BallSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("BallSpringArm"));
  BallSpringArm->SetupAttachment(RootComponent);

  BallCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("BallCamera"));
  BallCamera->SetupAttachment(BallSpringArm);

}

And there is a blueprint that inherits from this class.

614f67715b392040411181.png
I'm trying to give this ball physics for moving up and down by turning on physics and forbidding movement along the x, y coordinates. But I ran into a small problem:
When trying to simulate physics on a SphereComponent, the physics works correctly, but the restrictions on the ball are not applied and it just falls.

614f68e645292041624477.png
614f6930e3b71310520168.png
And when trying to simulate physics on a StaticMesh, the ball behaves exactly as I wanted, but it just "falls off" from the rest of the components.

614f6a2d59e74426524392.png
I would really like to understand why the limiters do not work when simulating on SphereComponent and why the ball "falls out" from SphereComponent when simulating on StaticMesh (if the explanation takes a long time, then links to specific documentation are enough, at this stage I'm just not sure where even to look there ). Is it possible to solve my problem head-on or is it easier to implement the class differently?

UPD: User Quark pointed me in the right direction, the problem was solved by the fact that the root component needed to be made StaticMesh, instead of SphereComponent. But the question still stands. What if it were necessary to leave the SphereComponent as the root component. Is it good practice to use a StaticMesh as a Pawn's root component?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question