Hi! SensitiveCube is here. I’ll explain how to make an object to face the player (like C4D’s ‘Target’ or Maya and 3dsMax’s ‘look at’) in STYLY with Playmaker and Unity. Also this entry describes simple texture animation with ShaderForge. Enjoy 😀
In the beginning, I’ll show you the assets such as models and texture maps. Next section is how to set up (or rigging) the laser with playmaker. Thirdly, we make simple texture animation with Shader Forge. Lastly, check the package in STYLY and Done!.
First thing first. Let’s check the assets for this entry. In the scene, there are three objects and material each. You can export FBX File menu > Export… > FBX(.fbx). In Export Setting window, turn off all General checkbox and turn on Textures and Materials in Additional. Type ‘Laser01.fbx’ and save it. Also need three textures for each models. These are simple grayscale images.
Go to unity and import these assets. Select Laser01 in Project window and hit the Extract Materials in Inspector window.
I want this laser keeps looking the player. What functions we need are, First : get Players position, Second : change the direction of Laser to Player in every flame. ‘Get Main Camera’ and ‘Look At’ actions can do this.
Before editing the final model, create this function with simple objects. Left click Hierarchy window and click Create Empty. ‘GameObject’ will be appear. change this name to ‘LaserParent_pm’. Left click Hierarchy again, select 3D Object > Cylinder. make sure the Cylinder is child of LaserParent_pm in Hierarchy window. Select LaserParent_pm in Hierarchy and open the Playmaker editor. simply add state and select State 1. Add two actions for the state, ‘Get Main Camera’ and ‘Look At’. Select ‘Get Main Camera’ and click Store Game Object tool out. Hit New variables and type ‘mainCamera’ and hit Create variable. Goto Look at acton. Click ‘=‘ icon left side of Target Object. Select mainCamera variable and turn off ‘Keep Vertical’. Make sure the Every Frame is checked.
Easy way to check this is, push Play button and goto Scene tab. When playing, You can check this by moving Main Camera in Scene window. Keep mind. The positon will be reset when stop playing. It looks work but the direction is wrong. Stop play mode and select Cylinder in Hierarchy window. Go to inspector window and set Rotation X to 90. If hit Play again, the Cylinder will face to the camera.
Eventually, Assign this function to Laser. Delete the Cylinder in Hierarchy and add Laser01 to LaserParent_pm. If direction is wrong, You can adjust by changing the value of rotation.
This section shows that how to create materials and shaders with Shader Forge. Two shades are needed. typeA : simple emissive shader and typeB : simple animated shader. In this entry, I’ll explain how to make shader typeB only. If you want to get more details, please check previous post.
In unity, open the ShaderForge window and hit New Shader. Select Unlit on left end of window and name it ‘laserCone’. Add 2D texture property and connect R to Opacity. Change name of 2D texture node to ‘alphaTexture’ and add smoke texture. Hit yellow triangle in Console area on left side of window. Apply this shader to cone material check in scene view.
Back to ShaderForge window. I want to add animation. In other word, to slide this texture horizontally by time. Additional five nodes are needed.
1. External Data > Time
2. Geometry Data > UV Coordinates
3. Constant Vectors > Vector 2
4. Arithmetic > Add
5. Arithmetic > Multiply
Next ScreenShot explain how to connect these nodes. The point is changing UV value by Time. If you want to change speed, change Vector 2 value. For example, if set ‘2 , 0’ animation speed will be double time. Othre why is connect Time:t to Multiply:A instead of Time:t/20. In this case, the speed became 20 time faster.
Before close shaderForge window, make sure OpenGL ES 3.x in shader setting is checked.
Let’s Upload to STYLY. Drag ‘LaserParent_pm’ to Project window and make it Prefab. Right click ‘LaserParent_pm’ prefab in Project panel and hit the ‘Upload prefab to STYLY’. After wile, move to online STYLY editor. You will find the prefab in ‘My Models’(Asset > 3D Models > My Models). In the editor, the Asset is facing not the ’Start Position’ but editor view. Don’t worry, It is ok because the Laser faces in ‘Main Camera’ of editor view.