How to implement a petting feature?

So I’m working on a game where you can pet an animal to improve it’s mood. I’m trying to figure out the best way (or just the way in general) to do this.

I’d like to have the player approach an animal, hold down left click and drag it across the animal to “pet” it and restore it’s mood or whatever.

So far I have Left Click event (with Tick as the Enter on the gate), I perform a trace to make sure I’m hitting the animal, I make sure it’s within a minimum distance, and then I don’t quite know what to do. I think what I would like to know is how to check how far the mouse has moved while having maintained a trace with an animal actor. That way I can do something like: “Check if minimum mouse move distance has been met, if true restore 10 mood.” Any suggestions?

You need to achieve three objectives: i) determine what the player’s looking at, ii) send a signal when the petting button is clicked, iii) determine if the animal was petted for a long enough distance to be happy.

I created an example for you based on the FPS blueprint template, check the gif here: Petting a cow on Make a GIF

You need to modify the MyCharacter blueprint, create a blueprint interface to allow the character to communicate with the animal (I named mine “InteractionInterface”). You need to create a function inside that interface with a vector input (mine is called “Interact”). Then you need to configure the animal’s blueprint props (called class properties in 4.7 preview) and add the interface to it. It’s all shown in the screenshots I’m attaching. I created a cube-cow that starts jumping for 3 seconds when petted for 20 cm. You can’t pet it again until it stops jumping.

Oh btw thanks for this! I’ve been busy with other things so I haven’t tried it out yet, but this looks just like the thing I need! Thanks a bunch! I can’t wait to try it out!

Cheers, good luck with your project.