- Home /
Detect the mouse swept direction and adding force to object.
Hello ,
I want to detect the mouse swept direction and addForce to that object along that direction when touch is released. See the SwipeExample on this demo : http://dl.dropboxusercontent.com/u/23073684/Blog/InputTouches/WebPlayer/WebPlayer.html
I am throwing a weapon when the touches have ended , The code is :
if(!weapon.rigidbody)
{
weapon.AddComponent("Rigidbody");
weapon.transform.parent = Scrap.transform;
weapon.rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
weapon.rigidbody.constraints = RigidbodyConstraints.FreezePositionZ;
weapon.rigidbody.mass = 4;
weapon.rigidbody.AddRelativeForce(weaponForceDirection * 8000);
weapon.tag = "Weapon";
}
in the weaponForceDirection Vector3 , I want to pass the direction .
I have declared weaponForceDirection and set its values as [0,0,-1]. in x,y,z.
A change in y value gives the required direction for me , like 0.1 to 0.4 gives angles [10 to 60] (as seen in protractor) and -0.1 to -0.4 gives angles in the [-10 to -60] .
So I want my y - direction to be changed depending on the swipe ranging from 0.1 to 0.4 upward and -0.1 to -0.4 downward.
Thanks in Advance.
Your answer
Follow this Question
Related Questions
Unity 2D Mobile Game Drawing Mechanic 0 Answers
How do I detect where touches are (Mobile) 1 Answer
Gameobject touch function is still detected on an overlayed Button UI 0 Answers
How to touch, move and rotate 3D objects in XZ? 1 Answer
What's the right way to detect double tap on a phone? 0 Answers