Create a VR template project, no starter content
Set Input action and referencing:
Add the following 4 inputs in controllers action mappings:
Open VRInteractionBPI, add 8 new functions named X/Y/B/A Pressed, and Released
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
Set the nodes from Input Action Y, X, A, B to the corresponding held component GET node
Command as FaceButtonInputMaps
Magent gun import
Import the mesh from folder, choose do not create material
Import texture, create M_MagGun material to connect
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
Change collision in details of MagnetReachShape to overlap all dynamic
Add Physics Constraint child under MagnetReachShape, name as GrabConstraint
move it as the same position as the reach shape sphere
change its linear motor and angular motor value as follow:
make sure angular limit are set to free
Go to its event graph:
Delete spawn the projectile nodes:
Select all nodes in Play Haptic Effect, R click on the final node, collapse to Function
Name the function as PlayHapticEffect, open it
Grab scale input in PlayHaptic Effect to Play Haptic Effect output, rename the input as Haptic Intensity
Back to event grpah, delete the play haptic effect node and command first
Delete the highlighed 4 nodes below too:
Add event tick node, go to class default, make sure Start with tick enable is checked
Start with the graph below, type get is held to get the target node
Continue
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
Add a 2nd static mesh, called Highlight → choose sphere mesh, scale up to 1.9 (bigger than the sm ball)
Create a holographic material named as Mtl_Highlight,
create its mtk instance
Open material, set follow:
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
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
Go to the magnetic actor event graph
Select hightlight component, tick hidden in game in detail
select OverlapDetect comp, R click, choose below event to create the node
Use the same method to create End overlap node too, connect as below
select SM ball comp, enable stimulate physics and disable gravity
Select Class default on top, type tag, add follow tag:
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:
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
Set Grab constraint referencing by magnet reach sphere, and breakhit result
so when overlap, will hold the object, when release, will drop the object
ending node. add haptic effect:
Add Animation on gun:
Import the backward and forward rotation of magent gun animation
Continue the mag gun graph with animation
For Forward movement:
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
Go to input, Axis Mapping, and delete Oclus Touch R A Press (if any)