Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Changes on UProjectileMovemenentComponent.Velocity does not affect its direction

I'm learning Unreal Engine and I'm developing Pong game to learn a lot!!

I have a problem, it I change UProjectileMovemenentComponent.Velocity in OnHit event it doesn't affect it.

Here is my class:

      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
     // Our root component will be a box that reacts to physics and interact with physical world.
     UBoxComponent* CollisionComp = CreateDefaultSubobject<UBoxComponent>(TEXT("BallBoxComponnent"));
     RootComponent = CollisionComp;
     // This extents the box from the origin. The value is 10.0f because the static mesh size is 20.0f.
     // And the distance from the origin, that is in the middle of box, to box's sides is 20.0f /2.0f = 10.0f.
     CollisionComp->InitBoxExtent(FVector(10.0f, 10.0f, 10.0f));
     // Create a mesh componnent so we ca see where our ball is.
     UStaticMeshComponent* BallVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BallVisualRepresentation"));
     // Enable collisions
     CollisionComp->SetCollisionProfileName(TEXT("BlockAll")); // or BoxComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block);
     // Set up a notification for when this component hits something blocking.
     CollisionComp->OnComponentHit.AddDynamic(this, &ABall::OnHit);
     // Add a visual cuboid to see it.
     static ConstructorHelpers::FObjectFinder<UStaticMesh> CuboidVisualAsset(TEXT("'/Game/Meshes/SM_Ball.SM_Ball'"));
     if (CuboidVisualAsset.Succeeded())
         static ConstructorHelpers::FObjectFinder<UMaterial> WhiteMaterial(TEXT("'/Game/Materials/M_White.M_White'"));
         if (WhiteMaterial.Succeeded())
             BallVisual->SetMaterial(0, WhiteMaterial.Object);
     // Create our movement component.
     // Use a ProjectileMovementComponent to govern this projectile's movement
     ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("BallProjectileComp"));
     ProjectileMovement->UpdatedComponent = CollisionComp;
     ProjectileMovement->InitialSpeed = 1500.f;
     ProjectileMovement->MaxSpeed = 1500.f;
     ProjectileMovement->bRotationFollowsVelocity = true;
     ProjectileMovement->bShouldBounce = true;
     // Do not lose velocity when bounces.
     ProjectileMovement->Bounciness = 1.0f;
     // Set velocity vector to move ball to -Y axis.
     ProjectileMovement->Velocity = FVector(0.0f, -1.0f, 1.0f);
     // Disable gravity.
     ProjectileMovement->ProjectileGravityScale = 0.0f;
     // Enable constraint movement to a plane.
     // Constraint direction to plane Y-Z (so that X cannot change).
     // Done with a vector with X=1.
     ProjectileMovement->SetPlaneConstraintNormal(FVector(1.0f, 0.0f, 0.0f));
 // Called when the game starts or when spawned
 void ABall::BeginPlay()
 // Called every frame
 void ABall::Tick( float DeltaTime )
     Super::Tick( DeltaTime );
 void ABall::OnHit(UPrimitiveComponent * HitComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, FVector NormalImpulse, const FHitResult & Hit)
     if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL))
         ProjectileMovement->Velocity.Z = 1.0f;

Maybe the problem is that I'm using bShouldBounce = true.

Any idea about how it doesn't change its Velocity?

Product Version: UE 4.14
more ▼

asked Jan 27 '17 at 06:47 AM in C++ Programming

avatar image

30 13 21 23

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

The problem here is that the Velocity has a extremely slow value.

Use this instead:

 ProjectileMovement->Velocity.Z = 300.0f;

I always answering my own questions.

more ▼

answered Jan 27 '17 at 07:25 PM

avatar image

30 13 21 23

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question