Throw Object 3D (Unity Asset) — highly customizable Advanced Throwing System for Unity. You can throw object forward or in any direction with custom force, a center of mass, and 80+ other throwing parameters. 2 Modes. 2 Demos. 10 Throwing Objects.
- 1 Features of Throw Object 3D
- 2 Package Contains
- 3 Package is a Part of Unity Assets
- 4 Use Cases
- 5 Throwing System: 80+ Customizable Parameters
- 6 Tutorial
- 7 Testing
- 8 Support
- 9 Changelog
Features of Throw Object 3D
All modules are designed independently to keep the Unity Asset extendable & easy to understand:
- Cross-platform: Mobile, Desktop (Mouse).
- 2 Throwing Modes: “Click Or Tap” (Easy) and “Flick” (or Swipe: Hard).
- 80+ Customizable Parameters — sensitivity, force, torque, delays, position, rotation, fading, etc.:
- for all Throwing Objects at once;
- for each Throwing Object individually.
- 2 Demos: Mobile, Desktop (FPS).
- 7 Events.
- 10 customized Throwing Objects:
- Weapons: Axe, Sword, Broken Sword;
- Balls: Basketball, Brick Balls (Grey, Red);
- Miscellaneous: Coin, Shovel, Horseshoe, Tree/Branch.
- Easy implementation of your own Throwing Objects.
- Dynamic Sound System — play Sounds based on speed, pitch, and volume factors of Throwing Objects upon:
- Dynamic Material System:
- Layer Changing (to avoid unwanted collisions).
- Demo Scene with Throwing for Desktop & Mobiles with Static Camera.
- Demo Scene with Throwing for Desktop (FPS): Walk, Run, Jump, Throw.
- Menu Scene.
- Loading Screen to switch scenes seamlessly.
Check the Map of Unity Assets to choose the product that best suits your needs.
Package is a Part of Unity Assets
- Games in the style of Pokemon GO, Can Knockdown, Paper Toss Boss, Paper Bin AR;
- AR Unity Assets by Makaka Games;
- FPS, VR Games with Throwing Objects;
- Survival Games;
- Any of your Bold Fantasies.
Throwing System: 80+ Customizable Parameters
Throwing System consists of 4 control scripts that are completely customized already in Demo Scenes.
1. Random Object Pooler
RandomObjectPooler.cs — independent script: Object Pool, performance optimization technique through Objects Reusing. It’s used by ThrowControl.cs. All Throwing Objects are created at the Scene Start from prefabs and used throughout the Scene Session.
- initPooledAmount — to regulate Object Count in the Scene at Start.
- poolParent — parent object contains Throwing Object until Throw and after Reset. It’s useful when Dynamic Camera (FPS, AR): to follow camera movements before Throw.
- isDebugLogging — to log key moments when Development Build.
- positionAtInit — to instantiate Throwing Objects at Start outside the Game Area, to Avoid Collisions between Throwing Objects and with Other Physical Objects.
- rotationAtInit — to set the object direction before appearing. It’s used in AR Shooter (docs) without Throwing System.
Prefabs of Throwing Objects are set in Unity Editor by default.
If you have dynamic gameplay & you need to change prefabs programmatically before initialization outside the Throwing System, use the next functions of ThrowControl.cs (AR Basketball (docs) uses such function due to different ball prefabs for different AR Engines: AR Foundation & AR Camera Lite (docs)):
- SetPrefabBeforeInit(GameObject gameObject),
- SetPrefabsBeforeInit(GameObject gameObjects).
- prefab — single object for instantiating. When it equals None then prefabs are used instead. It’s relevant for temporary testing the target prefab when you are using multiple prefabs.
- areRandomizedObjectsWhenCreating — when you need a random instance count of possible Throwing Object prefabs for every Scene Start.
- areRandomizedObjectsWhenGetting — when you require a random Throwing Object instance for every Throw.
- prefabs — multiple objects for instantiating.
- OnInitialized — when all initial pool operations are completed.
2. Throw Control
ThrowControl.cs — main script that manages the Throw & all Throwing Objects on a scene through Object Pool. The script uses disabling and enabling the following nodes: Colliders, Triggers, Renderers.
To Get the Count of Throwing Objects, use GetObjectCount() function.
The higher the last position of the mouse cursor (or finger) during the click (or tap), the greater the strength of the throw. Throwing System completely works on Desktop as well as on Mobiles.
Click Or Tap
In this mode, the Game Object is thrown in the direction of the click (desktop) or tap (mobile).
For the FPS game, there is an option for fixing the input position in a specific place on the screen (by default in the center of the screen). FPS Desktop Demo uses CharacterController (Throw force takes into account the speed of the player’s movement).
Is Full Path For Flick?
If it’s false then it allows fast flicks only: positions in the last and previous frames are taken into account.
- Initialize Object Pool,
- Initialize Throwing Objects,
- Get First Throw (Start the Throwing Cycle):
- Get Next Throw,
- Fade In,
- Fade Out,
- Next Events have ThrowingObject as a parameter. So you have more flexibility with access to instances of ThrowingObject.cs in outer functions assigned to Events.
The only script that starts coroutines. Because of coroutines behavior, it’s impossible to place some methods inside ThrowingObject.cs. OOP doesn’t work in this case, but we have a stable throwing with Object Pool.
3. Throwing Object
ThrowingObject.cs — script that contains basic functions and parameters to operate Throwing Object.
This script must be attached to each Throwing Prefab (check tutorial).
- flagCustom: for Any User Logic outside the Throwing System.
- monoBehaviourCustom: it’s useful to assign a specific control script for a unique type of Throwing Object and access to it outside the Throwing System.
Example: BasketballBallControl.cs in AR Basketball (docs) & Basketball Game (docs).
- positionInViewportOnReset: spawn position [x, y].
- cameraNearClipPlaneFactorOnReset: spawn position [z].
- audioDataCustom: array for customizing any dynamic Audio Data based on speed, pitch, and volume factors of Throwing Object. Access from ThrowControl.cs or ThrowingObject.cs with PlayRandomSoundDependingOnSpeed() function:
- 0 Element is used for Throw Audio (Whoosh).
- Other Elements can be used for any Custom Game Logic (e.g., for Customizing Collisions with different surfaces (floor, wall, etc.). Examples with using outside the Throwing System dynamically and uniformly: AR Throw & Score (docs), AR Basketball (docs), Basketball Game (docs)).
Rotation (Torque) & Center of Mass
There are some nuances with Rigidbody.centerOfMass when rotation.
If you use Mesh Collider for Throwing Game Object and your mesh is ideally symmetric, then it’s the perfect case and the game object will throw naturally.
If you use Mesh Collider for Throwing Game Object and your mesh is asymmetric, then you will have unnatural throw behavior when rotation.
1. Custom Center of Mass. You can indicate Custom Center of Mass manually in the Editor. Unity Package contains some examples with Custom Center of Mass and Tools for Debugging it Visually (you can also turn on the Gizmos in the Game view to facilitate the debugging). There is no magic function that calculates the right Center of Mass.
2. Simple Forms of Colliders. You need to use one or more simple forms of colliders (box, sphere, etc.) placing them on the same Throwing Game Object and along the straight line. So in this case, you will have the right center of mass & right rotation.
Unity allows you to use only convex mesh colliders. In some cases, it is not what you need because the collider by default can cover more space than the object itself in some points. In order to quickly & automatically get a convex mesh collider for complex objects, use Technie Collider Creator.
4. Material Control
MaterialControl.cs — an independent script that implements Fading (Dissolving) VFX for Throwing Objects: it’s used by ThrowingObject.cs. You can use it for Fading outside Throwing System (Examples: Ring, Ring Holder, Net, Backboard, Pole in AR Basketball (docs) & Basketball Game (docs)).
Here you can control Fading In & Fading Out with Full Control of Value, Delay, Time & Speed for Indicated Shader Parameter. Actually, you can change any Float Parameter in the shader over time.
Default Materials for Throwing Object is still placed in the Mesh Renderer component.
- materialDataCustom – array for Customizing Material Changing for Any Custom Game Logic (e.g., fail, win). Access from ThrowControl.cs or ThrowingObject.cs with SetMaterial() function.
SetMaterial() function is used instead of Color Changing with SetColor() function to avoid memory allocations. So if you plan to change the Colors of Throwing Objects in the Runtime outside the Throwing System, you need to create Materials with Target Colors in advance.
Examples with using outside the Throwing System dynamically and uniformly:
AR Throw & Score (docs), AR Basketball (docs), Basketball Game (docs).
There are 3 Custom Shaders with “Slice Guide” Texture for Fading of Game Object and its Shadow.
Check [Your Material] > Shader > Custom > Makaka Games:
- Diffuse (Dissolving),
- Bumped Diffuse (Dissolving),
- Particles Cutout Transparent — for Transparent Textures (Example: Net in AR Basketball (docs) & Basketball Game (docs)).
This tutorial is relevant for Throw Object 3D 5.2+.
Tutorial for the previous version can be found only in the asset folder.
Getting Started with Throw Object 3D
Folders & Files in the package by default:
- Makaka Games.
If you have any issues with the first launch then just Reach Support with Invoice Number and Get Help.
If you read this tutorial from PDF, first check the latest docs online to get actual information.
- Create New Unity Project with Unity 2021.3.4 & “3D” Template.
- File > Build Settings > iOS, Android, Standalone (PC, Mac) or WebGL > Switch Platform.
- Download and import Throw Object 3D into Unity.
- Warning Windows:
- Click “Import” to overwrite the Project Settings with predefined ones.
- Click “Install/Upgrade” for Package Manager Dependencies.
- Warning Windows:
- Next Packages are provided with Unity Package Manager, and they are already installed for this Asset by default. If packages are missing (Warning Window did not appear) then install them again with Unity Package Manager (with advanced settings enabled: “Pre-release Packages” & “Show Dependencies”):
- TextMesh Pro 3.0.6:
- Always Required: Window > TextMeshPro > Import TMP Essential Resources.
- TextMesh Pro 3.0.6:
- Reopen Unity Project.
- Open Scene: Makaka Games > Throw Object 3D > Scenes > Demo.
- Test in the Unity Editor or Build for Mobile or Desktop.
Creating your own Throwing Object Prefab
- Create Prefab with a template:
- Select the Game Object on the Scene & Customize it:
- Indicate Mesh of your 3D Model in Mesh Filter component,
- Customize Material in Mesh Renderer component (duplicate previous Material in the Project window and indicate here to separate different Throwing Objects),
- Customize Fading in Material Control component,
- Customize Colliders:
- Indicate Mesh in Mesh Collider component (or in more suitable collider component);
- Option: Customize the Center of Mass for more natural Throwing.
- Customize the Transform component as you wish.
- Apply Changes to Prefab.
- Delete Game Object from Scene.
- Option: Add Asset Label (ThrowingObject) for Prefab for convenient searching in the Project window.
- Add Prefab to Random Object Pooler component of ThrowingPoolControl Game Object.
- Throw Object Forward in “Play Mode”.
How to Keep Game Objects in Scene after the Throwing?
Here is the result video after applying manipulations in this section.
By default, Throwing Objects are not destroyed during the game due to Object Pool pattern with Object Reusing. Initially, the system is designed so that objects disappear after a certain time to save your device’s memory. Note that objects in pool are instantiated in advance, before you can click start button.
You can achieve the desired result by setting a large number of objects in the pool and a large reset delay, while disabling the fading:
- Target Throwing Object prefab > Material Control component > Is Parameter Changing On At Start > Uncheck (we are disabling the fading here).
- ThrowingPoolControl Game Object on Scene:
The system is designed with the Object Pool pattern, so you can’t set these values in inspector to protect you from too large values, long loading at start & low performance of your game, but you can fix the restrictions inside the script in field attributes.
Tested with Platforms
- iOS on iPhone XS Max;
- Android on Samsung Galaxy A71;
- WebGL in Google Chrome.
Check the current version of Throw Object 3D on Asset Store.
The latest versions will be added as soon as possible.
- Opportunity to Set a target prefab/prefabs of Throwing Objects before Initialization outside Throwing System with the next functions of ThrowControl.cs (it’s used in AR Basketball (docs) due to different ball prefabs for different AR Engines: AR Foundation & AR Camera Lite (docs)):
- public void SetPrefabBeforeInit(GameObject gameObject),
- public void SetPrefabsBeforeInit(GameObject gameObjects).
- Unity 2021.2.16.
- Opportunity to use a Target Audio Source when Playing Sounds from audioDataCustom related to Throwing Object with public void PlayAudioRandomlyDependingOnSpeed(int index, bool isStoppedBeforePlay, AudioSource audioSource = null) & ThrowingObject.cs.
Example: AR Basketball (docs), Basketball Game (docs).
- Dynamic and Unified Operating of Data for Different Throwing Objects (examples with using outside the Throwing System: AR Throw & Score (docs), AR Basketball (docs), Basketball Game (docs)):
- audioDataCustom – Array for Customizing Collisions with different surfaces (e.g., floor, wall) or for Any Custom Game Logic; merged with deprecated Whoosh Audio. Access from ThrowControl.cs or ThrowingObject.cs with PlayRandomSoundDependingOnSpeed() function.
- materialDataCustom (MaterialControl.cs) – Array for Material Changing for Any Custom Game Logic (e.g., fail, win). Access from ThrowControl.cs or ThrowingObject.cs with SetMaterial() function.
- RandomObjectPooler.cs: Split areRandomizedObjects boolean flag into 2 flags:
- areRandomizedObjectsWhenCreating – when you need a random instance count of possible Throwing Object prefabs every Scene Start.
- areRandomizedObjectsWhenGetting – when you require a random Throwing Object instance for every Throw.
- Retrieving Count of Throwing Objects with ThrowControl.cs > GetObjectCount().
- Tools for Debugging the Center of Mass Visually in Unity Editor. If the Center of Mass by Default is not correct, you can use these tools for improving Center of Mass with Custom value.
- Unity 2021.2.13.
- Instantiating Throwing Objects at Start outside the Game Area in target positionAtInit (RandomObjectPooler.cs) — Avoid Collisions between Throwing Objects and with Other Physical Objects more accurately:
- Split Reset of Position:
- On Init – to Target Position at Instantiating.
- On Throw – to Camera Position.
- Split Layer Changing option into 2 stages & 3 states:
- On Init,
- On Throw & On Reset.
- Split Reset of Position:
- Consolidating the Same Code of Registering Throwing Object in Throwing System into RandomObjectPooler.cs.
- ThrowControl.cs > OnInitialized() Event is raised more accurately: in the correct frame after all operations.
- Shovel Throwing Object: Custom and Accurate Collider for Shovel.
- Unified Menu Scene for All Scenes.
- Loading Animation for Start Buttons.
- Unity 2021.1.20;
- New Flag: “Is Throwing Blocked When Clicking UI”;
- Improve Project Settings to modern standards of New Unity Project;
- Fix Resetting Rotation & Position from RigidBody to Transform to be compatible with AR Foundation camera (for AR Throwing (docs));
- Fix Secondary Throw in “Flick” Mode when clicking on current Throwing Object after throw and before appearing of new throwing object;
- Fix Throwing in “Flick” Mode when clicking outside any object with Collider after correct flicking throw;
- Fix Throwing in “Flick” Mode when !isFullPathForFlick: clicking on empty space doesn’t cause throwing now;
- Fix “NullReferenceException” when “None” Game Object is assigned in Inspector of Random Object Pooler;
- Fix Missing Textures.
- New Platform: WebGL Support (Tested in Google Chrome);
- Unity 2021.1.12;
- Fix Dissolving VFX.
- Optimization: TextMesh PRO for all texts.
- Unity 2021.1.6.
This version adds performance improvements by more effective handling of materials, shaders, fading & caching, so it’s incompatible with previous versions of Asset.
- Improve Dissolving (Fading) VFX. Separate Independent Script for Throwing Objects: MaterialControl.cs — so you can use it for Fading outside Throwing System (Examples: Ring, Ring Holder, Net, Backboard, Pole in AR Basketball GO (docs) & Basketball Game (docs)).
- 1 Material Instead of 2: No Memory Allocation while Fading.
- 3 Custom Shaders with Shadow Fading & “Slice Guide” Texture for Fading:
- Fading In & Fading Out with Full Control of Value, Delay, Time & Speed for Indicated Shader Parameter.
- Add public event Actions for Each Trowing Object in ThrowingObject.cs:
- Improve all public Events in ThowControl.cs: add ThrowingObject as a parameter. So you have more flexibility with access to instances of ThrowingObject.cs in outer functions assigned to Events.
- Add a Custom MonoBehaviour field in ThrowingObject.cs: it is useful to assign a specific control script for a unique type of Throwing Object and access to it outside the Throwing System. Example: BasketballBallControl.cs in AR Basketball GO (docs) & Basketball Game (docs).
- Now SetMaterial() function is used instead of SetColor() functions all over the system to avoid memory allocations. So if you plan to change Colors of Throwing Objects in Runtime outside Throwing System you need to create Materials with Target colors in advance. Example: Red Fail Material in AR Basketball GO (docs) & Basketball Game (docs).
- Unity 2019.3:
- Fix Mesh Collider of Horseshoe.
- AudioData class and PlayRandomSoundDependingOnSpeed() function. Now you can easily declare Sound Settings in your own scripts to Play Sounds based on the speed of Throwing Objects. It’s helpful when you implement a dynamic sound system when Throwing Objects collide with Floor, Walls and Other Game Objects.
- Function: public int GetObjectCount ();
- Function: public void SetColor (Color color, GameObject to);
3.16 (Bug Fixing):
- Audio Delay (Latency) on Mobiles;
- “Index Out of Bounds” error in Input.GetTouch(0) for Mobiles;
- Debug.LogWarning() for unknown platforms.
- Option: Custom Flag in ThrowingObject.cs for Any User Logic.
- Option: Tag Selector for ThrowControl.cs to set a custom tag for all objects in the pool.
- Unity 2019.1;
- Unity 2018.3;
- Move cameraNearClipPlaneFactor to ThrowingObject.cs to customize the whole position (X, Y, Z) of Throwing Object prefab in one place;
- Fix enabling and disabling colliders for compound Throwing Prefabs.
- Unity 2018.2;
- Fix errors: When Flick Mode you just click on the object without finger position change.
3.4 (Layer Changing in Throw Control):
Actual for quick Throwing to neutralize mutual collisions.
- ON / OFF,
- Layer Mask on Throw,
- Layer Mask on Reset,
3.3 (Throw Customizations in Throw Control):
- Input Sensitivity,
- Force Factor Extra,
- Torque Factor Extra,
- Torque Angle Extra,
- Parent on Throw.
3.2 (“Flick” Mode Customizations in Throw Control):
- Option: Is Full Path:
- If it’s false then it allows fast flicks only (positions in the last and previous frames are taken into account);
- Lerp Time Factor On Touch.
- FPS Demo integrated with CharacterController (Desktop);
- Throw force takes into account the speed of the player’s movement;
- Fixing an input position in a specific place on the screen (by default in the center of the screen).
3.0 (New Architecture: Throw Control):
Main Control Script (Throw Control) operates Object Pool & All Throwing Objects now (Throwing Object Script is attached to each Throwing Object prefab).
- Initialize Pool,
- Initialize Throwing Objects,
- Get the First Throw,
- Get Next Throw.
- Customizations in Throw Control:
- Throw Mode;
- Events with Delays:
2.6 (Rotation Customizations):
- Option: Rotate Object in Throw Direction;
- Rotation on Reset:
- Position in Viewport On Reset.
2.4 (Center of Mass Customizations):
- Custom Center of Mass,
- Logging of Center of Mass by Default.
2.3 (Torque Customizations):
- Torque Axis,
- Torque Angle,
- Torque Factor,
- Max Angular Velocity at Awake.
2.2 (Force Customization):
- Force Factor,
- Force Direction Extra.
- “Click or Tap” Throwing Mode for Desktop & Mobiles;
- Throwing Mode.
2.0 (Object Pool — Throwing of Multiple Objects):
- Prefabs Using:
- Single (actual for Testing target prefab; None => Multiple),
- Generation order for Multiple Prefabs:
- In random order,
- In the right order;
- Pool Parent,
- Init pooled amount,
- Event (OnInitialized).
1.3 (Dynamic Sound System):
Sound System depending on Speed of Throwing Object.
- Array for randomly selecting Sounds,
- Speed Clamping,
- Pitch (Minimum & Factor),
- Volume Factor.
1.2 (Fade Out option for Thrown Objects):
- ON / OFF,
- Event (OnInitialized).
- Desktop version: throw object with the mouse. Use it for Standalone apps or for testing of mobile apps in Unity Editor.
1.0 (“Flick” Throwing Mode for Mobiles):
- Throwing of Single Object in “Flick” Mode for Mobiles (AR Basketball GO — Unity Asset).