- Home /
How can i implement the exhaust effect prefab i have in the back of my spaceship ?
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);
}
}
}
Answer by Adam-Mechtley · Nov 25, 2016 at 12:36 PM
Hi @Chocolade! In the Inspector for your particle emitter, the "Simulate in Worldspace" checkbox is ticked, which means the particle ignores the transform matrix hierarchy it inherits. Turn that off and it should follow your ship just fine.
For your second question, a lot of the features in the Legacy particle system never had proper API points added, which is part of the reason the Legacy system is being deprecated (per the warning in the Inspector). That said, it looks like unfortunately when the documentation was updated to put in appropriate warnings, links were removed to API points on ParticleEmitter. For example, there is the Emit () method, which might give you something to work with. I'll file a bug with the docs team.