I don’t have any images right now as I’m not at my development computer, but i’ll try and explain it.
Inside of the Vehicle blueprint (not the animation blueprint). I have created 2 keypress events, one for up and one for down movement (Q and Z).
I have a variable called “ForkHeight” which is a vector.
I have set up a Timeline node that has a float track called “trackfloat” with a max value of 10, min value of 0.
When I hit Q (up), it connects to the “play” input of the Timeline, then from the timeline’s update output, I have a set node for “ForkHeight”.
I have a “Lerp(Vector)” node which ranges from 0,0,0 to 0,0,10, which takes in the “trackfloat” from the timeline, to the Alpha input of the lerp node.
Then from the lerp node, the vector output goes into the “ForkHeight” setter node.
Also, from the Q key press, I drag the “released” output to “stop” on the Timeline.
For the Z key press (down), I simply just drag the pressed connection to “reverse” on the Timeline, and on “released”, once again, I connect to “stop” on the Timeline.
Inside the Vehicle animation blueprint, I created a vector variable once again with the name “ForkHeight”.
Inside of the event graph, I create a “Try Get Pawn Owner” (you may need to untick context sensitive for this to appear), I drag the return value out and cast to the forklift actor, then I drag out from the actor output and “Get ForkHeight”. I then set the animation blueprint’s “ForkHeight” variable to the same value as from the forklift blueprint.
Then if you don’t already have an “Event Blueprint Update Animation” node, create one. Then drag from it’s output to the “cast to” node, then from the “cast to” node, to the setter node for “ForkHeight”.
Now go to your Anim Graph.
You should first have “Mesh space ref pose”, connected to a “Transform (Modify) Bone” for the bone which raises your forks (in my case, it’s called “ForkJoint”). This takes in a Translation vector. Connect your “ForkHeight” variable to the Translation vector. Next, click on the Transform (Modify) Bone node itself and in it’s properties, make sure to set the Translation Mode to BMM Additive, and make sure the Translation Space is set to Component Space.
The next node in the anim graph is “Wheel Handler”, then simply connect this up to “Final Animation Pose”.
Lastly, inside of the fork lift’s physics asset, you need to make sure that the ForkJoint physics type is set to Kinematic (I also disabled gravity).
Then at least in my case, I go to constrain mode, I select the ForkJoint and change it’s Constraint Bone 2 to a wheel or something other than the root joint, and it seems to work fine. However setting to root or none means that the fork will move, but the vehicle cannot be driven, nor does it simulate physics correctly.
That should be it for a very basic forklift, but as you mentioned, you could add your own fork assets and attach them to a socket if you wanted. I don’t know if there are any drawbacks to doing so however.
I find that the problem that I have now with the forklift is that if I lower the forks down on top of a physics body, the physics bodies kind of get pushed into the ground, before spazzing out and flying off into space along with my forklift.
I put in a line trace that is done when I move the forks down to check when the fork is about to hit an object, which stops the forks if there is something it will collide with on the down movement. But it’s not ideal.