- Home /
Question by
TotalPixel · Jul 12, 2014 at 02:52 PM ·
rigidbody2d
More force depending on if mouse is clicked or held
Hi all, im trying to get a script to add a jump force to a character if the mouse is clicked and a boost forward force if the mouse is held.
im having a lot of trouble with this and been trying all different ways but cant get it to activate the jump force.
any help with this will be greatly appreciated.
if (Input.GetKeyDown ("mouse 0")) {
boostactive = false;
}
if (Input.GetKey ("mouse 0"))
{
holdcount++;
if(holdcount < 10)
{
boostactive = false;
}
if(holdcount > 10)
{
boostactive = true;
rigidbody2D.velocity = Vector2.zero;
rigidbody2D.AddForce(boostForce);
}
}
if (Input.GetKeyUp ("mouse 0")) {
if(boostactive = false)
{
rigidbody2D.AddForce (jumpForce);
holdcount = 0;
}
if(boostactive = true)
{
boostactive = false;
rigidbody2D.AddRelativeForce(new Vector2(-300,0));
}
}
Thanks.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613153856im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to rotate a Rigidbody2D faster than 4500 (degrees/s)? 0 Answers
Trying to clamp the movement of a rigidbody2D 1 Answer
unity2d cannot create if gravity level 1 Answer
No changing Linear Drag (.linearDrag) on rigidbody / rigidbody2D in code? 1 Answer
Will centerOfMass rotate my Rigidbody2D with gravity. 0 Answers