Playing with Physics, where to start?

ey up

just out of curiosity, i want to start messing with physics. all the info i have found is about blueprints and mainly about constraining 2 actors together.
however i would like to dig into the core of physx simulation and see what craziness i can come up with.

so very generally, what areas of the source are interesting to play with?
are there any c++ examples around i could take a look at?

thanks
sorry about the vagueness

I guess this is a good place to start.

Maybe i could be of more help if you explain a litle futher what you are thinking about doing.
.

that is a good place to start thanks

no end goal in mind, i just want to have a play with it

oh dear, other than #include “PhysXIncludes.h” every line of that code throws errors :frowning:
guess it was for an earlier engine version

Did you include the modules for it?
In YourProjectName.Build.cs


PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore", "PhysX", "APEX"});

If it do not solve the issue, please post the error messages you are getting.

yep i did
im using 4.6 and a lot of stuff seems to have changed (so im guessing from the error comments)

heres the errors


1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public\MyDestructibleActor.h(28): error C3861: 'DrawDebugPoint': identifier not found
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public\MyDestructibleActor.h(40): error C2065: 'GEngine' : undeclared identifier
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public\MyDestructibleActor.h(40): error C2227: left of '->AddOnScreenDebugMessage' must point to class/struct/union/generic type
1>          type is 'unknown-type'
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public\MyDestructibleActor.h(45): error C2065: 'GEngine' : undeclared identifier
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public\MyDestructibleActor.h(45): error C2227: left of '->AddOnScreenDebugMessage' must point to class/struct/union/generic type
1>          type is 'unknown-type'
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public/MyDestructibleActor.h(28): error C3861: 'DrawDebugPoint': identifier not found
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public/MyDestructibleActor.h(40): error C2065: 'GEngine' : undeclared identifier
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public/MyDestructibleActor.h(40): error C2227: left of '->AddOnScreenDebugMessage' must point to class/struct/union/generic type
1>          type is 'unknown-type'
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public/MyDestructibleActor.h(45): error C2065: 'GEngine' : undeclared identifier
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public/MyDestructibleActor.h(45): error C2227: left of '->AddOnScreenDebugMessage' must point to class/struct/union/generic type
1>          type is 'unknown-type'
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(10): warning C4996: FPostConstructInitializeProperties is deprecated and was renamed to FObjectInitializer. Please use that type instead.
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(10): error C2084: function 'AMyDestructibleActor::AMyDestructibleActor(const FObjectInitializer &)' already has a body
1>          C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public\MyDestructibleActor.h(14) : see previous definition of '{ctor}'
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(24): warning C4996: 'ADestructibleActor::DestructibleComponent': DestructibleComponent should not be accessed directly, please use GetDestructibleComponent() function instead. DestructibleComponent will soon be private and your code will not compile. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.
1>          D:\GitHub\UnrealEngine-4.6\Engine\Source\Runtime\Engine\Classes\PhysicsEngine/DestructibleActor.h(25) : see declaration of 'ADestructibleActor::DestructibleComponent'
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(24): error C2027: use of undefined type 'UDestructibleComponent'
1>          D:\GitHub\UnrealEngine-4.6\Engine\Source\Runtime\Engine\Classes\PhysicsEngine/DestructibleActor.h(9) : see declaration of 'UDestructibleComponent'
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(24): error C2227: left of '->ChunkInfos' must point to class/struct/union/generic type
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(26): error C2065: 'Each' : undeclared identifier
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(26): error C2228: left of '.Actor' must have class/struct/union
1>          type is 'unknown-type'
1>  -------- End Detailed Actions Stats -----------------------------------------------------------

is my code just incase im a complete spaz and cant copy/paste/edit or something
‘PHYSICSMESS_API’ was generated by ue4 when i added the class from the editor, i just added the content from the wiki page
.h


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "PhysicsEngine/DestructibleActor.h"
#include "MyDestructibleActor.generated.h"

/**
 * 
 */
UCLASS()
class PHYSICSMESS_API AMyDestructibleActor : public ADestructibleActor
{
	GENERATED_BODY()
	
protected:
	virtual void Tick(float DeltaTime) override;

	//Drawing!
public:
	FORCEINLINE void DrawPoint
		(
		const FVector& Loc,
		const float& Size = 7,
		const FColor& Color = FColor::Red,
		const float Duration = -1.f
		) const {
		DrawDebugPoint(
			GetWorld(),
			Loc,
			Size, //thickness
			Color,
			false,
			Duration
			);
	}

	FORCEINLINE void ScreenMsg(const FString& Msg)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *Msg);
	}

	FORCEINLINE void ScreenMsg(const FString& Msg, const FString& Msg2)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("%s %s"), *Msg, *Msg2));
	}
};


.cpp


// Fill out your copyright notice in the Description page of Project Settings.

#include "PhysicsMess.h"
#include "MyDestructibleActor.h"
//~~~~~~~~~~~~~~~~~~~~~~~~
//	   PhysX 			
#include "PhysXIncludes.h" 
//~~~~~~~~~~~~~~~~~~~~~~~~

AMyDestructibleActor::AMyDestructibleActor(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP)
{

}
//Tick
void AMyDestructibleActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	//~~~~~~~~~~~~


	//Draw All Centers to the screen!
#if WITH_PHYSX
	ScreenMsg("Got into PhysX!!!");
	for (FDestructibleChunkInfo& Each : DestructibleComponent->ChunkInfos)
	{
		physx::PxRigidDynamic* Actor = Each.Actor;

		if (Actor)
		{
			PxTransform Trans = Actor->getGlobalPose();
			PxVec3& PxLoc = Trans.p;

			FVector Location(PxLoc.x, PxLoc.y, PxLoc.z);

			DrawPoint(Location);

			ScreenMsg("physx loc", Location.ToString());
		}
	}
#endif // WITH_PHYSX 
}






check the main header file of your project. for example mine is just Elium.h

change
#include “EngineMinimal.h”
to
#include “Engine.h”

this changed in 4.4 IIRC

and yes, this is one of those things you only find about by browsing AnswerHub :frowning:

well that certainly cut down the errors thanks,
however


1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(10): warning C4996: FPostConstructInitializeProperties is deprecated and was renamed to FObjectInitializer. Please use that type instead.
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(10): error C2084: function 'AMyDestructibleActor::AMyDestructibleActor(const FObjectInitializer &)' already has a body
1>          C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Public\MyDestructibleActor.h(14) : see previous definition of '{ctor}'
1>C:\Users\bob\Documents\Unreal Projects\PhysicsMess\Source\PhysicsMess\Private\MyDestructibleActor.cpp(24): warning C4996: 'ADestructibleActor::DestructibleComponent': DestructibleComponent should not be accessed directly, please use GetDestructibleComponent() function instead. DestructibleComponent will soon be private and your code will not compile. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.
1>          D:\GitHub\UnrealEngine-4.6\Engine\Source\Runtime\Engine\Classes\PhysicsEngine/DestructibleActor.h(25) : see declaration of 'ADestructibleActor::DestructibleComponent'
1>          D:\GitHub\UnrealEngine-4.6\Engine\Source\Runtime\Engine\Classes\PhysicsEngine/DestructibleActor.h(25) : see declaration of 'ADestructibleActor::DestructibleComponent'
1>  -------- End Detailed Actions Stats -----------------------------------------------------------

edit:
after fixing those errors it compiles!!!

is the .cpp that compiles


// Fill out your copyright notice in the Description page of Project Settings.

#include "PhysicsMess.h"
#include "MyDestructibleActor.h"
//~~~~~~~~~~~~~~~~~~~~~~~~
//	   PhysX 			
#include "PhysXIncludes.h" 
//~~~~~~~~~~~~~~~~~~~~~~~~

//Tick
void AMyDestructibleActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	//~~~~~~~~~~~~


	//Draw All Centers to the screen!
#if WITH_PHYSX
	ScreenMsg("Got into PhysX!!!");
	for (FDestructibleChunkInfo& Each : GetDestructibleComponent()->ChunkInfos)
	{
		physx::PxRigidDynamic* Actor = Each.Actor;

		if (Actor)
		{
			PxTransform Trans = Actor->getGlobalPose();
			PxVec3& PxLoc = Trans.p;

			FVector Location(PxLoc.x, PxLoc.y, PxLoc.z);

			DrawPoint(Location);

			ScreenMsg("physx loc", Location.ToString());
		}
	}
#endif // WITH_PHYSX 
}

thanks ever so much for the help