Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice
Dismiss Notice
The Commercial: Jobs, Commercial: Job Seekers, and Non-Commercial Collaboration. subforums will be closed to new posts beginning on October 31st. Until that time we recommend users cross-post any existing job seeking, hiring, and seeking collaborator threads on Unity Connect.

i need a script for shooting missiles

Discussion in 'Non Commercial Collaboration' started by sdsmith64, Sep 8, 2010.

  1. sdsmith64


    Nov 16, 2009
    what I need is to have the player shoot a rocket at a target using a movable cross-hair cursor. (think "Missile Command") But the rocket has to follow the curve of the planet for a short distance (to the edge of the visible horizon) using the left mouse button(rapid fire if held down). How much would you charge for this script?

    the large saucers (bad guys) are sucking the "energy" from the planet (and don't move)


    To make the player ship follow the planet surface I'm using a script that i got from this post:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    4. public class OrbitPlanet : MonoBehaviour {
    5.    public float rotationSpeed = 120.0f;
    6.    public float translationSpeed = 10.0f;
    7.    public float height = 2.0f;          //height from ground level
    8.    private Transform centre;            //transform for planet
    9.    private float radius;               //calculated radius from collider
    10.    public SphereCollider planet;         //collider for planet
    12.    void Start () {
    13.       //consider scale applied to planet transform (assuming uniform, just pick one)
    14.       radius = planet.radius * planet.transform.localScale.y;
    15.       centre = planet.transform;
    16.       //starting position at north pole
    17.       transform.position = centre.position + new Vector3(0,radius+height,0);
    18.    }
    20.    void Update () {
    21.       //translate based on input    
    22.       float inputMag  = Input.GetAxis("Vertical")*translationSpeed*Time.deltaTime;
    23.       transform.position += transform.forward * inputMag;
    24.         //snap position to radius + height (could also use raycasts)
    25.       Vector3 targetPosition = transform.position - centre.position;
    26.       float ratio = (radius + height) / targetPosition.magnitude;
    27.       targetPosition.Scale( new Vector3(ratio, ratio, ratio) );
    28.       transform.position = targetPosition + centre.position;
    29.       //calculate planet surface normal                    
    30.       Vector3 surfaceNormal = transform.position - centre.position;
    31.       surfaceNormal.Normalize();
    32.       //GameObject's heading
    33.       float headingDeltaAngle = Input.GetAxis("Horizontal") * Time.deltaTime * rotationSpeed;
    34.       Quaternion headingDelta = Quaternion.AngleAxis(headingDeltaAngle, transform.up);
    35.       //align with surface normal
    36.       transform.rotation = Quaternion.FromToRotation( transform.up, surfaceNormal) * transform.rotation;
    37.       //apply heading rotation
    38.       transform.rotation = headingDelta * transform.rotation;
    39.    }
    40. }