- Home /
Question about Scripting a slingshot mechanic
I have been attemping to create a game mechanic where you click on the player, and a new object is created called a PaintBag. The paintBag is then pulled back like a slingshot, and released when the mouse comes up. My problem is that I am wanting the object to follow the mouse only within a certain limit (as in, as far as the stretch of the slingshot). COuld anyone suggest what is wrong with the script?
void PullBack(){
Vector2 catapultToMouse = mousePlace - playerPos;
if (catapultToMouse.sqrMagnitude > maxDrawDistance) {
mouseRay.direction = catapultToMouse;
mousePlace = mouseRay.GetPoint (maxDrawDistance);
}
mousePlace.z = 0f;
transform.position = mousePlace;
}
Here's the update function. activate is a variable set to true when the player is clicked.
void Update () {
if (activate) {
PullBack();
}
}
Comment
Your answer
Follow this Question
Related Questions
Help with 2D physics script 1 Answer
Multiple Cars not working 1 Answer
Photon position syncing 0 Answers
Checking for collision with 2D objects/sprites 3 Answers
While Moving Left or Right my character falls more slowly. 2 Answers