I just started a thing in unity… and this is all the code i have(attatched to the player):
using UnityEngine;
using System.Collections;
public class MoveScript : MonoBehaviour {
public float forwSpeed;
public float backSpeed;
public float rotateSpeed;
public GameObject projectilePrefab;
public GameObject projectile;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float vertical = Input.GetAxis("Vertical")*Time.deltaTime;
rigidbody.AddRelativeForce(new Vector3(vertical<0?vertical*backSpeed:vertical*forwSpeed,0,0));
float horizontal = Input.GetAxis ("Horizontal")*Time.deltaTime;
rigidbody.AddRelativeTorque (new Vector3 (0,horizontal*rotateSpeed,0));
if(Input.GetKeyDown(KeyCode.Space)){
shootProjectile();
}
}
void shootProjectile(){
projectile = (GameObject)Instantiate (projectilePrefab, transform.position, Quaternion.identity);//i'm going to replace identity when i come up with something good (i suck with quaternions)
projectile.rigidbody.AddForce(new Vector3())//here is where i dont know what to do
}
}
It’s kind of a low friction vehicle top down shooter with a single projectile, where 2 players try to shoot each other in an 1v1 arena.
The problem is i dont know how to give the projectile force based on the player’s local rotation/position, i just want it to launch out in the X axis.
Does anyone know how i would go about doing that?
Thank you… and i am sorry for the messy otganization of this post