Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include "UMod.h"
  2. #include "SyncedMapPhysicsEntity.h"
  3.  
  4.  
  5. // Sets default values
  6. ASyncedMapPhysicsEntity::ASyncedMapPhysicsEntity()
  7. {
  8. // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
  9. PrimaryActorTick.bCanEverTick = true;
  10. }
  11.  
  12. // Called when the game starts or when spawned
  13. void ASyncedMapPhysicsEntity::BeginPlay()
  14. {
  15. Super::BeginPlay();
  16.  
  17. if (Role != ROLE_Authority) {
  18. DisableComponentsSimulatePhysics();
  19. }
  20. }
  21.  
  22. // Called every frame
  23. void ASyncedMapPhysicsEntity::Tick(float DeltaTime)
  24. {
  25. Super::Tick(DeltaTime);
  26.  
  27. if (Role == ROLE_Authority){
  28. //Send physx simulation data
  29. FVector loc = GetActorLocation();
  30. FRotator rot = GetActorRotation();
  31. PhysicsPacket(loc, rot);
  32. } else {
  33. //Interpolate between cur pos and new pos received from server
  34. //FVector a = GetActorLocation();
  35. //FVector b = desiredPos;
  36. //FVector newPos = FMath::Lerp(a, b, 1.5F);
  37. SetActorLocation(desiredPos);
  38.  
  39. //FVector a1 = GetActorRotation().Vector();
  40. //FVector b1 = desiredRot.Vector();
  41. //FVector lerped = FMath::Lerp(a1, b1, 1.5F);
  42. SetActorRotation(desiredRot);
  43. }
  44. }
  45.  
  46. void ASyncedMapPhysicsEntity::PhysicsPacket_Implementation(FVector newPos, FRotator newRot)
  47. {
  48. desiredPos = newPos;
  49. desiredRot = newRot;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement