- Home /
How can i set AddRelativeForce relative to how fast/slow im moving my mouse?
Hi, I want to open a door by dragging with my code. The door retains a constant velocity though no matter how fast or slow i drag my mouse. Is there someway to set the force relative to my mouse speed? Thanks!
function Update()
{
onMouseDrag();
}
function onMouseDrag()
{
if(Input.GetMouseButton(0))
{
rigidbody.drag = 0;
if(Input.GetAxis("Mouse X")>0)
{
rigidbody.AddRelativeForce (Vector3.forward * 1);
}
if(Input.GetAxis("Mouse X")<0)
{
rigidbody.AddRelativeForce (Vector3.back * 1);
}
}
else
{
rigidbody.drag = 3;
}
}
Sorry, i mean relative to mouse DISTANCE travelled. So for example if i stare at the dorr and turn 90 degrees, the door will be fully open regardless of how fast i dragged! SOme ideas would be great.
Answer by Inok · Dec 29, 2014 at 03:33 PM
Probably better to do this through joint. Short concept:
Add to haracter for example hinge joint component.
Set by script "connected body" of joint to your door rigidbody.
Enable joint connection while pressing mouse button and you have physic interaction with door.
Answer by mikhailovic · Dec 30, 2014 at 03:50 AM
Sorry silly question, i just fiddles with the values of Drag and the multiplying vector and got the effect i was looking for. Nothing wrong in the code.
Your answer
Follow this Question
Related Questions
adding drag to a relative force 0 Answers
Touch controlled ice puck 0 Answers
Calculating the force required (Rigidbody) 3 Answers
Add force based on drag speed 4 Answers
How to negate this force? 2 Answers