Announcement

Collapse
No announcement yet.

Add Force / Impulse Not responding.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Add Force / Impulse Not responding.

    I've got two different projects both of them have projectiles that come out of a gun. I've tried via code as well as BP including even copy and pasting the BP Nodes between projects, and In the first project projectiles come out of the gun as expected move in the correct direction etc. In the second projects they just fall from the gun with no velocity? I've checked to see if any of the physics settings are different, and can't see anything different. Any Ideas?

    Code:
    AActor* bullet = GetWorld()->SpawnActor(mBullet, spawnLocation, rotation); 
    	
    	TArray<UStaticMeshComponent*> component; 
    	bullet->GetComponents(component); 
    	if (component.Num() > 0)
    	{	
    		FVector force = (component[0]->GetForwardVector() * 5000.0f);
    		component[0]->AddImpulse(force);
    	}
    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	96.4 KB
ID:	1217794

    Thanks,

    Rich.

    #2
    Update: If I AddImpulse() on every frame, instead of just BeginPlay() The bullet speeds up over time. AddForce() is similar when I provide a higher multiplier, (which seems accurate as to what the functions do) but the bullet stays the same speed even though I'm adding force each frame.

    Comment


      #3
      Update 2:

      Alright so I'm not sure if this is normal or not, I would say no since in my other projects the projectile worked fine, however if I set a flag (ForceHasApplied = false) and in the first tick function
      Code:
      if(!ForceHasApplied)
      {
          staticMesh->AddImpulse(staticMesh->GetForwardVector() * 50)
          ForceHasApplied = true;
      }
      Then it functions as expected.

      Any idea's why it works fine in the first tick, but not in BeginPlay(), and apparently only in this project?

      Comment

      Working...
      X