x


Rotating projectile

I have a simple game where a gorilla throws a banana ... here is the overall script thus far:

var force:int;
var angle:int;
//var prefabBanana:Transform;
var temp:int;
var temptwo:int;
var prefabBanana : GameObject; 
//var gorilla : GameObject;
var elevationAngle : Vector3;
var throwForce : int;

function OnGUI ()
{

        if(GUI.Button(Rect(10, 50, 80, 20), "Launch!!")) {
        Launch();
        }

        var text = GUI.TextField(Rect(10, 10, 50, 20), angle.ToString());
        var texttwo = GUI.TextField(Rect(10, 30, 50, 20), force.ToString());

        if (int.TryParse(text, temp)){
        angle = Mathf.Clamp(0, temp, 360);
        }

        else if (text == "") angle = 0;

        if (int.TryParse(texttwo, temptwo)){
        force = Mathf.Clamp(0, temptwo, 360);
        }

        else if (texttwo == "") force = 0;
}

function Launch()
{

    elevationAngle = Vector3(0,0,angle);
    throwForce = force *100;

    var banana : GameObject; 

    banana = Instantiate(prefabBanana, transform.position, Quaternion.identity);

    var elevation : Vector3 = Quaternion.Euler(elevationAngle) * transform.forward;

    new banana.rigidbody.AddForce(elevation * throwForce);

        }

It all works correctly, except I would like the banana to travel while rotating on I believe is my z-axis in a clockwise rotation. Kinda stumped on what approach to take for this ... thanks!

more ▼

asked Apr 08, 2011 at 12:09 AM

SlapnutsGT gravatar image

SlapnutsGT
3 6 4 7

BTW I tried animating and was having some issues with keeping banana on the correct path... I figured there would be a simpler approach with scripting... if animation provides a faster approach I'm all ears.

Apr 08, 2011 at 12:11 AM SlapnutsGT
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first
more ▼

answered Apr 08, 2011 at 12:11 AM

DaveA gravatar image

DaveA
33.1k 416 334 442

(comments are locked)
10|3000 characters needed characters left

try transform.roatate. if you do use this approach, then be sure to make the collider a child, otherwise it won't work.

more ▼

answered Apr 08, 2011 at 12:56 AM

zmar0519 gravatar image

zmar0519
1k 164 125 139

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3492
x2978
x350
x48
x37

asked: Apr 08, 2011 at 12:09 AM

Seen: 1468 times

Last Updated: Apr 08, 2011 at 12:09 AM