i need a script for shooting missiles

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

  1. sdsmith64

    sdsmith64

    New Member

    Joined:
    Nov 16, 2009
    Messages:
    27
    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)

    [​IMG]

    To make the player ship follow the planet surface I'm using a script that i got from this post:
    http://forum.unity3d.com/viewtopic....0&postorder=asc&highlight=orbitplanet&start=0


    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    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
    11.  
    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.    }
    19.    
    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. }