Game Development Community

How to draw a tire trail?

by Michele Condo' · in iTorque 2D · 03/27/2011 (11:59 am) · 13 replies

Hello!

I need to draw a tire trail, but I don't know how to doing.

I have a picture that represents a portion of a tire track bike. I need to find a way to draw the trail left by a tire of the bike.

I tried to use the clone, but the performance is very bad, so I was wondering if there was opportunity to do with a particle. If could do with a particle system, could someone tell me how to do it? I tried to mount the object particle to object "byke", but I do not understand how to make a particle that leaves a trail.

Or there is a way to draw a "line" with a image pattern.

Thanks in advance.


#1
03/27/2011 (12:44 pm)
Make a particle which draws the trail elements without movement every now and then, with a relatively long lifetime. Mount this on your vehicle.
#2
03/27/2011 (1:36 pm)
Hello!
I've tried, but don't work..

I've make a particle emitter, have set as follow:

Image : the image map have the part of trail tire.
Type: POINT (just try all other enums)
Orientation: ALIGNED
Fixed angle : 0.0
Pivot : 0.50 0.50
Force angle : 0.0
Fixed Aspect : True
Use Effect Emission : True
Intense Particles : False
Single particle : True
Attach Position : True
Attach Rotation : True
Rotate Emission : True
First in Front : False

After all, I've set Emitter Graph Particle Life Base e Variance to max in time and value graph.

I've mount the particle on my byke item, but when I move byke, but not work..

Does anybody tell me how to set emitter to doing a trail?

Tnx in advance.. I need really help..

#3
03/27/2011 (6:16 pm)
Can you post a screenshot of what it looks like?
#4
03/27/2011 (8:02 pm)
I'm almost positive you don't want "Attach Position". As the particle emitter moves, all of the particles will move with it.
#5
03/28/2011 (12:35 am)
Hi, I've tried to set to False the "Attach position" flag. But if I flag false this, also if I've mount the particle on the bike, the particle emitter don't move...

So, I post the picture that I've done with the "clone" method, to clone every update frame the trail tire, but this technique have a bad performance and bad result... I need to use particle I suppose, to have a good result.

This is the layer game:
dl.dropbox.com/u/15897235/Screenshot%20App/img1.png
This is the result using the clone to tire trail object:
dl.dropbox.com/u/15897235/Screenshot%20App/img2.png
This is the same result during make an arc with bike...
dl.dropbox.com/u/15897235/Screenshot%20App/img3.png
I think that using particle I can doing this better, but I've trouble to set and use particle in torque to doing a trail particle during moving an object...

I need help!
#6
03/28/2011 (6:19 am)
Does anybody know how do a particle that make this trail tire when the object emitter move?
#7
03/28/2011 (7:43 am)
There is some code in the Torque 2D demos. When I get to the office I will grab that code/particle effect and post it here. It should help out.
#8
03/28/2011 (9:22 am)
Thanks!

I will wait with hope your help! It would be very useful because I cannot make a particle of a track tire! I tried a lot but without right result.


#9
03/28/2011 (9:34 am)
Alright. So I have not tested this yet, but I might as well put this code up so we can debug it:

if (!isObject(ContrailBehavior))
{
   %template = new BehaviorTemplate(ContrailBehavior);
   
   %template.friendlyName = "Contrail";
   %template.behaviorType = "Effects";
   %template.description  = "This should be added to a particle effect. Plays the effect when the object it is mounted to is moving";
}

function ContrailBehavior::onBehaviorAdd(%this)
{
   %this.owner.enableUpdateCallback();
   %this.playing = false;
}

function ContrailBehavior::onUpdate(%this)
{
   %parent = %this.owner.getMountedParent();
   if (!isObject(%parent))
      return;
   
   if (t2dVectorLength(%parent.linearVelocity) >= 0.1)
   {
      %this.owner.rotation = -%parent.rotation;
      if (!%this.playing)
      {
         %this.owner.playEffect(false);
         %this.playing = true;
      }
   }
   else
   {
      %this.owner.stopEffect(true, false);
      %this.playing = false;
   }
}

1. Create a directory in projectFiles/game/scripts named behaviors
2. Add the above code a script file named contrail.cs
3. Save contrail.cs to the behaviors directory
4. Open the editor
5. Mount your particle effect to your bike
6. Enable UsesPhysics on both the object and particle effect
7. Add contrail.cs to the particle effect
8. Save and run

Make sure you are mounting the particle effect to your object and not to a background or another layer. Let me know how that works for you.
#10
03/28/2011 (10:22 am)
Hi, I've tried to use the script you post. The script work well, the tire trail appear only when bike move.

But the effect result is wrong for me, don't seems a trail tire.
I suppose my issue is in the particle emitter/effect, I can not make the effect of a tire trail well... and I don't find any help how to make a tire trail effect in torque... can you help me pls?
#11
03/28/2011 (12:55 pm)
@Michele - So it is definitely the particle effect then. I can send you the particle effect used for the code I posted, so you can open it up and check out the values. That might be the best way to start modifying your emitter to more closely resemble tracks.
#12
03/28/2011 (4:49 pm)
I'm curious by the way, does Torque/iTorque have any functionality exposed for loading images after level load and/or to edit the raw image data (procedural). Even if it's in C++, or would I have to wrap up the functions used to load levels etc?
#13
03/28/2011 (11:27 pm)
@Michael - Hi, tnx for your help, yes, I would appreciate if you send me the effect appropriate for use with the script you post before.
Can you send the particle effect at this e-mail pls? kabal_mcblade@hotmail.com

Really thanks for your help!