In the screenshot you can see in the Hierarchy i dragged the Engine(The exhaust effect prefab ) to be child of my spaceship but when running the game it’s not showing the effect.
If i will just drag the Engine to the Hierarchy not as child i will see the effect fine but i want to implement it on the back of my spaceship.
If i change the Engine position and put it a child of my spaceship i can then set it’s position to be on the spaceship but is there any way to set it automatic to be on the back of my spaceship ?
In the screenshot it’s the back of my spaceship and you can see in the scene window the Engine sit small on the ship top.
And i want it to be on the back on the two exhausts places.
UndamagedShip is the spaceship.
And the child Engine is the exhaust effect i want to add to it’s back.
And then i want to control from a script on the exhaust effect. In this script i tried to make acceleration to my ship when i press the p key. But i don’t want to use Rigidbody i just want to make that when i press the p key it will give some boost power speed to my spaceship and the exhaust effect will act more or less power according to how much i press the p key.
The Engine the exhaust effect i downloaded from here:
using UnityEngine;
using System.Collections;
public class ControlShip : MonoBehaviour {
public int rotationSpeed = 75;
public int movementspeed = 10;
public int thrust = 10;
bool isPKeyDown = false;
float acceleration = .0f;
Vector3 previousPosition = Vector3.zero;
Rigidbody _rigidbody;
// Use this for initialization
void Start () {
_rigidbody = GetComponent<Rigidbody>();
Debug.Log("Acc Speed: " + thrust);
}
// Update is called once per frame
void Update () {
var v3 = new Vector3(Input.GetAxis("Vertical"), Input.GetAxis("Horizontal"), 0.0f);
transform.Rotate(v3 * rotationSpeed * Time.deltaTime);
transform.position += transform.forward * Time.deltaTime * movementspeed;
if (Input.GetKey(KeyCode.Z))
transform.Rotate(Vector3.forward * rotationSpeed * Time.deltaTime);
if (Input.GetKey("p"))
{
isPKeyDown = Input.GetKey("p");
float distance = Vector3.Distance(previousPosition, transform.position);
acceleration = distance / Mathf.Pow(Time.deltaTime, 2);
previousPosition = transform.position;
_rigidbody.AddRelativeForce(0f, 0f, thrust, ForceMode.Acceleration);
}
}
void OnGUI()
{
if (isPKeyDown)
{
GUI.Label(new Rect(100, 100, 200, 200), "Acc Speed: " + acceleration);
}
}
}
