I’m a newbie - working on the Tanks tutorial. Have been following along fine, but my tank dust trails are not working when the tank is moving forward and backward. The trails emit fine during the turning operation. I suspect this has to do with the difference between MovePosition() and MoveRotation() and their affect on the particle system. I have tried virtually every setting on the particle system - disabling all modules except the renderer and the emission over distance. When dragging the particle system in the scene view, the emissions appear correctly. But, when I click play and use the keyboard to control the tank, the particles only emit on turning - not on movement.
Using 5.5.0p3
Look at the Particle System component of your dust objects (both left and right) and scroll to “Emiter Velocity”. Change it from Rigidbody to Transform.
I am facing the same issue right now. I’m a newbie too, but it seems that MovePosition() doesn’t affect the particles anymore (from version 5.5). I’m not sure but the Rigidbody velocity’s properties doesn’t update if the tank is moved by MovePosition(). Instead, using the AddForce() method the particles effect works (affecting the velocity property).
Looks like you want to change the emitter velocity to measure Transform instead of Rigidbody, likely because MovePosition doesn’t alter the Rigidbody velocity.
Disclaimer: At the time of writing, I have only completed up to the 5th section of the tutorial.
Using @DanielePattuzzi ‘s answer, I’ve fixed the problem of the explosion not pushing the tanks backwards enough, though I modify the game’s behavior in the process. I believe the problem was that the modified move function (shown below) was overwriting the tanks’ velocity from the explosion, resulting in the tank stopping after 1 physics tick.
private void Move()
{
// Adjust the position of the tank based on the player's input.
m_Rigidbody.velocity = transform.forward * m_MovementInputValue * m_Speed;
}
My solution was to have the move function modify the velocity instead of overwrite it.
public float m_maxSpeed = 10f;
public float m_Acceleration = 0.5f;
private void Move()
{
// Adjust the velocity of the tank based on the player's input.
Vector3 velocity = m_Rigidbody.velocity;
velocity += transform.forward * m_MovementInputValue * m_Acceleration;
Vector3 direction = velocity.normalized;
velocity = direction * Mathf.Min(Mathf.Abs(velocity.magnitude), m_maxSpeed);
m_Rigidbody.velocity = velocity;
}
What I do here is add an acceleration value to the velocity each tick depending on whether the input is forwards, backwards, or 0. I then cap this velocity with a max speed. The result is a tank that does not instantly change its speed, letting explosions push it around.
This change drastically changes how the tank handles, however. Increasing the acceleration brings the behavior closer to that of the original, but I have not figured out how to brake the tank (right now it just coasts to a stop)