2023
3D adventure game about a hamster trying to escape from the confines of its cage and house to be wild and free outside! This is a indie game I am working on with a team of other programmers, artists, and game designers.
This game has multiple interactions the main character (hamster) can perform. Among them are:
NOTE: this project is very much work in progress so this page will be updated as we progress further in development.
An example of the hamster interacting with an object in the world to push it out of the way so the hamster can keep walking. This involves sending out a box trace to look for an object to interact with, aligning the hamster to the object, attaching the object to the hamster, and finally locking the movement for the hamster to the forward vector of the object and optionally locking out left and right movement.
void AHHPushableInteractable::Interact_Implementation(AActor* Interactor) { // updates CanInteract, CurrentlyInteracting, and Interacting Actor Super::Interact_Implementation(Interactor); if (!IsValid(Interactor)) return; if (bCurrentlyInteracting) { if (InsideInteractionBox) { AttachCharacterToObject(Cast(Interactor)); }else { StopInteraction(); } }else { DetachCharacterFromObject(); } } void AHHPushableInteractable::AttachCharacterToObject(AHHCharacter * Character) { if (IsValid(Character)) { Character->AttachToInteractable(); LockedCharacter = Character; LockedCharacter->GetCapsuleComponent()->IgnoreActorWhenMoving(this, true); if (InsideInteractionBox) { AlignCharacterToInteractionBox(Character); FAttachmentTransformRules attachRules = FAttachmentTransformRules(EAttachmentRule::KeepWorld, EAttachmentRule::KeepWorld, EAttachmentRule::KeepWorld, true); AttachToComponent(Character->GetAttachPoint_Implementation(), attachRules); FHHRestrictedMovement AttachedRM = FHHRestrictedMovement(EnableForwardMovement, EnableBackwardMovement, EnableLeftMovement, EnableRightMovement, ForwardVectorArrow->GetForwardVector(), ForwardVectorArrow->GetRightVector()); Character->AttachedRestrictedMovement = AttachedRM; } if (DisableCameraRotation) { Character->EnableCameraControls = false; } } }
Since there is multiple mechanics that require interacting with objects (i.e. walls to climb, objects to push, cracks to squeeze through), we created an interface class that we can have other actors inherit so the hamster can interact with them in a standardized way.
Since this is an interface class, we are not implementing the functions here, we simply define them and then implement them in each class however that interaction object needs to be handled.
// This class does not need to be modified. UINTERFACE(MinimalAPI) class UHHInteractable : public UInterface { GENERATED_BODY() }; class HAMSTERHOUSE_API IHHInteractable { GENERATED_BODY() // Add interface functions to this class. This is the class that will be inherited to implement this interface. public: UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Interaction") void Interact(AActor* Interactor); UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Interaction") bool CanInteract(); UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Interaction") bool IsInteractingWithPlayer(); };