Did some digging and came up with one way to do it. There may be other (and maybe better) ways to do it but here it is.
Every PickupFactory has a PickupMesh which is the mesh of the item the PickupFactory holds. This mesh is being shown in-game when the item is ready for you to pick up, and at this point the PickupFactory is in the state Pickup. What you want to do in this state is to add any movement code you have and apply it to PickupMesh. The problem is that the PickupMesh is of type PrimitiveComponent which means it has no location property, and therefore you can't change the location of it. However, you can spawn an actor and attach PickupMesh to it. When you've done that, you can apply the movement code to the actor and the mesh will move with it.
Code:
class MeshHolder extends Actor;
simulated function Tick (float DeltaTime)
{
local vector NewLocation;
NewLocation = Location;
NewLocation.Z += Velocity.Z;
}
Code:
class MyPickupFactory extends PickupFactory;
var MeshHolder MyMeshHolder;
simulated function SetPickupMesh()
{
if ( InventoryType.Default.PickupFactoryMesh != None )
{
if (PickupMesh != None)
{
if (MyMeshHolder != None)
{
MyMeshHolder.DetachComponent(PickupMesh);
MyMeshHolder.Destroy();
}
PickupMesh = None;
}
PickupMesh = new(self) InventoryType.default.PickupFactoryMesh.Class(InventoryType.default.PickupFactoryMesh);
if (MyMeshHolder == None)
MyMeshHolder = Spawn(class'MeshHolder',self,,Location,,,);
MyMeshHolder.AttachComponent(PickupMesh);
if (bPickupHidden)
{
SetPickupHidden();
}
else
{
SetPickupVisible();
}
}
}
auto state Pickup
{
function ChangeDirection()
{
if (MyMeshHolder != None)
MyMeshHolder.Velocity.Z *= -1;
}
event BeginState(name PreviousStateName)
{
MyMeshHolder.SetLocation(Location);
MyMeshHolder.Velocity.Z = 5.0;
SetTimer(1.0,true,'ChangeDirection');
super.BeginState(PreviousStateName);
}
event EndState(name NextStateName)
{
ClearTimer('ChangeDirection');
super.EndState(NextStateName);
}
}
Bookmarks