AnyPortrait > Script > Physic Effect
Physics Modifier's physics effects can be controlled by script.
You can turn physical effects on or off, and you can further control external force and pull.
Turn physical effects on or off.
bool isPhysicEnabled : Whether the physics modifier is processed
Add a radial force based on the point.
It returns apForceUnit, then you have to add properties.
Vector2 pointPosW : The position where the force is applied (World coordinate system)
float radius : Radius of radial force
apForceUnit : Generated force
Adds a directional force.
It returns apForceUnit, then you have to add properties.
Vector2 directionW : The direction in which the force is applied (World coordinate system)
apForceUnit : Generated force
Adds a directional force.
It has a repetitive directional change that draws a sin curve with respect to the X and Y axes, making it suitable for expressions like wind.
It returns apForceUnit, then you have to add properties.
Vector2 directionW : The direction in which the force is applied (World coordinate system)
float waveSizeX : The maximum X value in the periodically changing direction
float waveSizeY : The maximum Y value in the periodically changing direction
float waveTimeX : The cycle in which the direction changes about the X axis
float waveTime : The cycle in which the direction changes about the Y axis
apForceUnit : Generated force
Make sure that there is currently added force.
bool : Whether there is added forces
The calculated force is measured at the input position.
Vector2 targetPosW : Position to be measured (World coordinate system)
Vector2 : Measured force vector
Eliminate all the forces you have added with the AddForce function.
Remove the specified force.
apForceUnit forceUnit : The force data you want to delete. You can get it as the return of the AddForce function.
Start "pull" by touch input.
Vector2 posW : Touch position (World coordinate system)
float radius : Radius to be pulled
apPullTouch : Objects distinguished by unique IDs with information about "pull by touch"
Updates the current position of the touch corresponding to the apPullTouch returned after the call to AddTouch.
Select using apPullTouch.TouchID.
int touchID : ID corresponding to the TouchID of apPullTouch returned from AddTouch
Vector2 posW : The position of the current touch
Updates the current position of the touch corresponding to the apPullTouch returned after the call to AddTouch.
Select apPullTouch by entering parameters.
apPullTouch touch, : The apPullTouch returned from AddTouch
Vector2 posW : The position of the current touch
Returns if there is a touch currently added.
bool : Whether there is an added touch
Returns an apPullTouch object with an ID corresponding to touchID.
int touchID : ID of touch event to find
Removes the touch event object that is calculating the pulling.
int touchID : ID corresponding to the TouchID of apPullTouch returned from AddTouch
apPullTouch touch : apPullTouch returned from AddTouch
Remove all touch events.
Remove all forces and touch events.
If you use the AddForce function, the force is not applied.
You need to include additional information in the return value of the AddForce function, apForceUnit.
You must call one of the SetPower functions and call either EmitLoop or EmitOnce.
public apForceUnit SetPower(float power)
: Add power.
public apForceUnit SetPower(float power, float waveSize, float waveTime)
: Adds a force that changes periodically by the amount of waveTime times the size of waveSize based on power.
public apForceUnit EmitLoop()
: Set as a sustained force.
public apForceUnit EmitOnce(float liveTime)
: Set as a power to disappear after the time of liveTime.
using UnityEngine;
using AnyPortrait;
public class PhysicsTest : MonoBehaviour
{
// Target AnyPortrait Object
public apPortrait portrait;
// Touch ID
private int _touchID;
void Start () { }
void Update ()
{
//----------------------------------------
// Force Events
//----------------------------------------
// Clear Force
if(Input.GetKeyDown(KeyCode.C))
{
portrait.ClearForce();
Debug.Log("Clear Force");
}
// Add Point Force
if(Input.GetKeyDown(KeyCode.P))
{
// Position : (0, 0)
// Radius : 10
// Power : 2000
// Live Time : 10 Sec
portrait.AddForce_Point(Vector2.zero, 10.0f)
.SetPower(2000)
.EmitOnce(10);
Debug.Log("Add Point Force");
}
//Add Waved Directional Force
if(Input.GetKeyDown(KeyCode.D))
{
// Direction : (1 +- 0.5, 0.5 +- 0.2)
// Power : 4000 +- 1000
// Loop
portrait.AddForce_Direction(new Vector2(1.0f, 0.5f), 0.5f, 0.2f, 5, 10)
.SetPower(4000, 1000, 25)
.EmitLoop();
Debug.Log("Add Waved Directional Force");
}
//----------------------------------------
// Touch Events
//----------------------------------------
Vector3 touchPosW = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
Vector2 touchPosW2 = new Vector2(touchPosW.x, touchPosW.y);
//Left Click -> Touch
if(Input.GetMouseButtonDown(0))
{
//Start Touch Event
_touchID = portrait.AddTouch(touchPosW2, 2.0f).TouchID;
Debug.Log("Add Touch (" + _touchID + ")");
}
else if(Input.GetMouseButton(0))
{
//Refresh Touch Position
portrait.SetTouchPosition(_touchID, touchPosW2);
}
else if(Input.GetMouseButtonUp(0))
{
//Release Touch Event
portrait.ClearTouch();
_touchID = -1;
}
}
}