- Home /
Trying to move an object when I click my LMB
I'm currently using: HookChild.rigidbody.AddRelativeForce(HookHit.point * speed);
Which worked somewhat. But still not completely right.
The problem is giving it a ForceMode sends it flying in the wrong direction, but not giving it a Forcemode makes it move very very slowly.
It sounds like you need to use something more like HookChild.rigidbody.AddForceAtPosition(transform.forward*speed,HookHit.point);
Doesn't seem to be working at all. I'll keep messing around with that.
Either A: It's not counting in speed. or B: It doesn't move towards HookHit.point.
Right now it's both.
Answer by Xtro · Aug 02, 2013 at 02:24 PM
I'd rather prefer to enable the IsKinematic flag on the rigidbody and make it move by transformation. After the dragging event ends, I'd disable IsKinematic back.
Even if the object a rigidbody, dragging it doesn't have to be a force movement.
He means set [ridigbody.is$$anonymous$$inematic][1] = true;
, then use trasform.Translate or directly modify the transform. Finally set is$$anonymous$$inematic = false
.
[1]: http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-is$$anonymous$$inematic.html
Oddly that still seems to cause that annoying snap movement.
if (Input.Get$$anonymous$$ouseButtonDown(0))
{
HookChild.rigidbody.is$$anonymous$$inematic = true;
if(Physics.Raycast(HookRay, out HookHit, 50.0f) == true)
{
HookShot = true;
Debug.DrawRay(HookRay.origin,HookRay.direction, Color.red);
Debug.Log("Hook was hit");
HookChild.Translate(Vector3.$$anonymous$$oveTowards(Player.position,HookHit.point,$$anonymous$$athf.Infinity));
Debug.Log(HookChild.rigidbody.is$$anonymous$$inematic);
//HookChild.rigidbody.AddForceAtPosition(HookChild.right * speed,HookHit.point);
RopeChild.localRotation = Quaternion.LookRotation(Player.transform.forward,HookHit.point);
RopeChild.localScale += rope$$anonymous$$oveTowards * Time.deltaTime;
}
}
So using HookChild.rigidbody.is$$anonymous$$inematic = true;
causes my HookObject to not be destroyed until the next time I use the Destroy(HookChild.gameObject)
again.
And just using the transform causes it to snap.
Your answer
Follow this Question
Related Questions
How to speed up my character? 0 Answers
Kinematics: Trying to get an object to land at a known point 1 Answer
Apply force and torque on different collider enter 0 Answers
Reuse a collision 0 Answers
Rigidbody force problem 1 Answer