I've been programming for a bit over a week now. I'm working on a 2D-scrolling shooter with 3D visuals. The idea is for the game area to fly around the 3D world. Hence, everything that happens gameplay-wise should happen in coordinates relative to the GameArea prefab.
I've managed to make the GameArea-prefab fly through the game world using iTween, I've managed to make the bullets parent themselves to the GameArea and I've SORT OF managed to make the bullets fire in the correct orientation. What's happening now is that the bullets behave like in the pictures below.
![alt text][1]
Also, since the problem seems so difficult to describe, I have decided to fraps it. Check out this video to better see what I mean: [Link][2].
Below is the code for the bullet. I've decided to make it do all the parenting itself, rather than to put huge ammounts of code in the GameArea object (currently named iTweenrider in code).
using UnityEngine;
using System.Collections;
public class Projectile : MonoBehaviour {
public float ProjectileSpeed;
public Transform iTweenrider;
// Use this for initialization
void Start () {
}
void Awake () {
transform.parent = iTweenrider;
//GameObject Projectile = Instantiate(Projectile,PlayerCannon ,Quaternion.identity);
//Projectile.transform.parent = iTweenrider;
}
// Update is called once per frame
void Update () {
float amtToMove = ProjectileSpeed * Time.deltaTime;
transform.Translate (iTweenrider.transform.forward * amtToMove);
//transform.TransformDirection (Vector3.forward * amtToMove);
}
}
In case I'm not making myself clear enough, the bullets SHOULD fly towards the center of the screen, regardless of how the gamearea flies around the environment, and bullets should allways have the correct orientetion (not fly out sideways from the cannons as they do now).
[1]: /storage/temp/20887-scrollingshooter4.jpg
[2]: http://www.youtube.com/watch?v=1tt37G3EiwE&feature=youtu.be
↧