Weird angles with slingshot script.

This is my slingshot script. After many days of tinkering. It is working… to an extent.
But the angles that it produces are weird. If someone can help me figure out the problem i would be gratefull.

Here is the script.

var ammo : GameObject;
var multiplier : int;
var spawnPosition : Vector3;
var draggedPosition : Vector3;
var shootVector : Vector3;


function Update () 
spawnPosition = ammo.transform.position;

/* function OnMouseDrag (){ammo.position = MouseCursor.mousePosition;} */

function OnMouseUp ()
var draggedPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

shootVector = spawnPosition.normalized - draggedPosition.normalized;
ammo.rigidbody.AddForce(shootVector * multiplier, ForceMode.VelocityChange);

Hmm, why are you “normalizing” positions? That does not make much sense, I fear.

Second … you seem to be using “Camera.main.ScreenToWorldPoint” in one place but not in another place. You’d have to use the same approach, the same paradigm, for both points.

Thirdly … this is more or less not how you do this sort of thing! You’re trying to do it the incredibly hard way. I for instance would not be able to do it like this, too hard.

Here’s all you do … it’s unbelievably simple:

one … you see your rock object OK. write a very short script call “Move Da Rock Baby” and attach that script (“Move Da Rock Baby”) to the rock.

What does “Move Da Rock Baby” do ? The ONLY THING IT DOED is allow the user to move the rock around with their finger. That’s it.

(That is a very basic idea in game engineering … you should have no trouble doing that.)

So do that and FORGET ABOUT IT!

Next! Write another simple behaviour and attach it to the rock starting position (to the slingshot “tip” OK?)

Call this one “Get Dat Angle”. It is so simple it has ONE LINE OF CODE. In Update, just figure the vector of where you are minus wherever the rock is. That’s it !

make the result a public variable you can see in the inspector or whatever

So you’re done. AT ANY TIME you have the angle you’re interested in, just grab it from the “Get Dat Angle” script at any time.

So, that’s how you do it.

Never, ever try to write code in Unity - just attach trivial “behaviors” (with one or two lines of code) to game objects, and freely add game objects as needs be.