Hi Guys,
Basically i need a characters tongue to shoot out towards a point on the screen the player clicks. After the click an object will shoot towards that point and on arrival, immediately move back towards the player. I have a sprite that is the graphics of the tongue and i need it to scale and rotate to the tongue shoot object as the object moves the screen point.
I’m having issues coding the scale and the rotation of the tongue sprite object, particularly the rotation.
Here’s the code i have so far:
function Update () {
var pos1 = GameObject.Find ("Player").transform.position;
var pos2 = GameObject.Find ("TongueHitBox").transform.position;
var angle = Mathf.Atan2(pos2.y , pos2.x ) * Mathf.Rad2Deg;
transform.position = pos1;
if (pos2 != pos1) {
var v3 = pos2 - pos1;
transform.position = pos1;
transform.localScale.x = v3.magnitude/3.0f;
transform.rotation = Quaternion.Euler (new Vector3 (0, 0, angle));
}
}
At the moment the object scales sort of correctly, a little bit too long but I think I can fix that… It’s more the rotation. When I shoot the tongue it spins around to a different direction depending on how long it is.
I’ve pretty much formed this entire script from snippets of other answers. I’m no math wizard, and having experimented with different values I was left no choice but to seek help!
Any help would be much appreciated!
Regards,
Genaza
Anyone else got an idea?
– boulderkock