- Home /
add force in a particular direction
Hello,
I have a game object to which a slider is attached. The player can rotate the game object and then using the slider decide on how much force is to be applied. Its something like a pool game. Where you can rotate the object to set and angle and drag behind the stick to decide how much power is to be put into the shot.
here is my code:
private void Fire()
{
fired = true;
marble.GetComponent<Rigidbody2D>().isKinematic = false; // p.s. marble is the object i want to move
forceToBe.x = currentLaunchForce; // force to be applied to the object
print(currentLaunchForce); // for debugg purposes
marble.GetComponent<Rigidbody2D>().AddForceAtPosition(forceToBe, areaOfImpact.forward);
// yes, i need AddForceAtPosition because, the player can choose where they want to hit the object.
// Reset the launch force. This is a precaution in case of missing button events.
currentLaunchForce = minLaunchForce;
fired = false;
}
the problem however is, that the object only moves towards the left, i want the object to move towards where the slider is pointing to.
any ideas on how to achieve this?
Much obliged
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612093030im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Relative Rotation 1 Answer
Vector3.forward only moves me in 2 directions when rotating 1 Answer
Player not facing the mouse correctly 1 Answer
GameObject facing fowards 1 Answer
Rotating wrong 0 Answers