Hand Functions

Magnet Gun/Telekinesis



Create a VR template project, no starter content

Set Input action and referencing:


Add the following 4 inputs in controllers action mappings:
image.png

Open VRInteractionBPI, add 8 new functions named X/Y/B/A Pressed, and Released
image.png

Open VR Pawn, copy and paste the following nodes from Input action trigger left and right nodes, duplicate 1 time:
X,Y button for left held component GET node, A,B button for right one
image.png
Set the nodes from Input Action Y, X, A, B to the corresponding held component GET node
image.png
Command as FaceButtonInputMaps

Magent gun import

Import the mesh from folder, choose do not create material
Import texture, create M_MagGun material to connect
image.png
Open the mesh, choose the material to apply on


Create magnet gun BP:


Duplicate Psitol BP template, change its mesh to magGun
Add a static mesh component called MagnetReachSphere (make sure set as movable), choose sphere shape and basicshape material
put it at the position between the magent,
move the muzzle location at the centre of the magnet
image.png
Change collision in details of MagnetReachShape to overlap all dynamic
image.png
Add Physics Constraint child under MagnetReachShape, name as GrabConstraint
move it as the same position as the reach shape sphere
image.png
change its linear motor and angular motor value as follow:
image.png
make sure angular limit are set to free
image.png

Go to its event graph:
Delete spawn the projectile nodes:
image.png
Select all nodes in Play Haptic Effect, R click on the final node, collapse to Function
image.png
Name the function as PlayHapticEffect, open it
Grab scale input in PlayHaptic Effect to Play Haptic Effect output, rename the input as Haptic Intensity
image.png
Back to event grpah, delete the play haptic effect node and command first
image.png
Delete the highlighed 4 nodes below too:
image.png
Add event tick node, go to class default, make sure Start with tick enable is checked
image.png
Start with the graph below, type get is held to get the target node
image.png
Continue
image.png

BP for Mesh as actor be magneted by the gun:


Add a new BP class actor, name as BP_MagneticActor
Add component SM Ball_01, choose the SM ball mesh
image.png
Add a 2nd static mesh, called Highlight → choose sphere mesh, scale up to 1.9 (bigger than the sm ball)
image.png
Create a holographic material named as Mtl_Highlight,
create its mtk instance
Open material, set follow:
image.png
add VectorParameter node, name as SelectColor, change to blue color
(hot key S+ left click) for param node, name as opacity, set to 0.5 default value
image.png
Apply this material in Highlight component in Magnetic Actor

Choose SM Ball component, change its collision preset to Physics Actor,
while for Highlight component, preset to Overlap all dynamic

Add Physic collision component under highlight, name as Overlap Detect
scale it up (2) larger than highlight
image.png

Go to the magnetic actor event graph
Select hightlight component, tick hidden in game in detail
image.png
select OverlapDetect comp, R click, choose below event to create the node
image.png
Use the same method to create End overlap node too, connect as below
image.png
select SM ball comp, enable stimulate physics and disable gravity
image.png
Select Class default on top, type tag, add follow tag:
image.png
Place the magnetic actor BP in the scene

Remained BP for magnetic gun


Go to MagGun event graph, continue the graph from out hit output on line trace node

For object being magneted when the gun point to it:

image.png

For mangeted object be thrown around by holding and releasing:
On trigger released, set hit actor to let things reset so that can grab new thing
Collaspe the 3 nodes below to new function, name as DropObject →connect to Close to Gate
image.png

Set Grab constraint referencing by magnet reach sphere, and breakhit result

so when overlap, will hold the object, when release, will drop the object
image.png
ending node. add haptic effect:
image.png


Add Animation on gun:


Import the backward and forward rotation of magent gun animation
Continue the mag gun graph with animation
For Forward movement:
image.png
For backward movement, duplicate relevant nodes and:
change play animation node to play as backward,
replace B,Y buttons to A,X buttons
Change Add node Y value from 20 to -20
Connect Gate enter to Sequence 1
image.png

Go to input, Axis Mapping, and delete Oclus Touch R A Press (if any)
image.png


Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.