XNA Creators Club Online
Page 1 of 3 (60 items) 1 2 3 Next >
Sort Posts: Previous Next

Post your JigLibX Vehicle modifications *added custom vehicle class*

Last post 17/11/2009 0:03 by gazwik. 59 replies.
  • 18/04/2009 10:46

    Post your JigLibX Vehicle modifications *added custom vehicle class*

    I have done quite a few but none better than this ultra simple one that adds rotational friction to the wheels.  Before, if you were on level ground, you could coast forever after letting off the throttle.

    if (driveTorque == 0) 
        { 
            angVel *= .97f; 
        }    
       

    Put this in Update() in the Wheels.cs right above angVel += driveTorque * dt / inertia.  If you want more friction multiply by a smaller number.  Less friction use a bigger number that's less than 1.

    I have a lot more that I'll add tomorrow.

    In the meantime post your mods!


    edit:
    I know there is a going to be a better way than to multiply angVel by a fraction of one but I'll figure that out after I get some sleep. 

    edit again:

    So, I couldn't sleep.  Looking at it again just proves that I should've gone to college.

    Here's the updated one:
                    if (driveTorque == 0) 
                    { 
                        float axleFriction = 5; // higher number = more rotational friction 
                        if (angVel > axleFriction) 
                        { 
                            if (angVel > 0) angVel -= axleFriction; 
                            else angVel += axleFriction; 
                        } 
                        else angVel = 0; 
                    } 
     
     



  • 19/04/2009 14:03 In reply to

    Re: Post your JigLibX Vehicle modifications

    Neat, I'll try that one.

    I had once started work on a system that allowed you to equip weapons on the car, for a car deathmatch type game (Streets of SimCity, Twisted Metal, Full Auto, etc). It never got far since I couldn't get JigLibX to play nice with the GameStateManagement sample... Did you get that to work?
    "No programmer can pick up a TV remote without thinking what it would take to add a stun gun. [...] Their motto is 'if it ain't broke, it doesn't have enough features yet'" - Scott Adams, The Dilbert Principle

    The signature that was too big for the 512 char limit
  • 19/04/2009 16:16 In reply to

    Re: Post your JigLibX Vehicle modifications

    I haven't used that sample.  What was the problem you were running into in that sample?  

    I have a similar system working based on the Innovative Engine from innovativegames.com though.  It seems to work fine.  At first I couldn't get the physics system to stop updating when I launched a pause gamescreen for instance.  I got that sorted though and the physics system picks up where it left off when the pause screen is closed.
  • 19/04/2009 16:18 In reply to

    Re: Post your JigLibX Vehicle modifications

    Well, that nothing was being rendered except for a blank screen, for one. I could never figure out what was going wrong... I'll have to take a second look at it now.

    I had looked at the InnovativeEngine before, but it doesn't support CarObjects out of the box. What did you do to add them?
    "No programmer can pick up a TV remote without thinking what it would take to add a stun gun. [...] Their motto is 'if it ain't broke, it doesn't have enough features yet'" - Scott Adams, The Dilbert Principle

    The signature that was too big for the 512 char limit
  • 19/04/2009 16:46 In reply to

    Re: Post your JigLibX Vehicle modifications

    (now keep in mind I had tried this a while ago when I didn't know much about camera matrices!) I can't believe how simple it was. I hadn't added the player's car object to the list of objects to update, so the chasecamera wasn't being updated which is why the screen was blank - the camera was underneath the terrain pointing the wrong way. :-P Maybe now I'll continue work on my Streets of SimCity type game...

    Well, sorry to derail your thread! I'm interested too in how other people are using JigLibX.
    "No programmer can pick up a TV remote without thinking what it would take to add a stun gun. [...] Their motto is 'if it ain't broke, it doesn't have enough features yet'" - Scott Adams, The Dilbert Principle

    The signature that was too big for the 512 char limit
  • 19/04/2009 23:28 In reply to

    Re: Post your JigLibX Vehicle modifications

    That's good.  As far as CarObjects in Innovation Engine I started working on my own CarActor class and then someone posted their own in the forums.  I just used theirs.  

    I'll be home in a few hours and then I'll post some code for a proper hand brake, how to get the car to drift and speed sensitive steering so you car isn't so touchy at high speeds.  
  • 20/04/2009 11:02 In reply to

    Proper Hand Brake and Adding Tuning Capabilities

    Proper Hand Brake and Top Speed Adjusment *updated*

    The standard vehicle class has a hand brake that locks the rear wheels, thereby creating some drag and slowing the car down.  That part is realistic.  What isn't realistic is the rear wheels still have full traction.  If you've ever pulled a hand brake in a car while moving you've notice that the rear end loses traction and wants to swing around causing a spin.  It can be useful for making tight 180 degree turns, orienting your car coming into a turn and for good 'ol fashioned fun.
     
    I've added a variable for adjusting the top speed of the vehicle. 

    We'll have to start out by adding to Car.cs (changes/additions underlined)
    namespace JigLibX.Vehicles 
     
        public class Car 
        { 
            enum WheelId  
            {  
                WheelBR = 0, 
                WheelFR = 1, 
                WheelBL = 2, 
                WheelFL = 3,  
                MaxWheels = 4  
            } 
            #region private fields 
            private Chassis chassis; 
            private List<Wheel> wheels; 
     
            private bool fWDrive; 
            private bool bWDrive; 
            private float maxSteerAngle; 
            private float steerRate; 
            private float wheelFSideFriction; 
            private float wheelRSideFriction;
            private float wheelFwdFriction; 
            private float wheelRwdFriction; 
            private float wheelTravel; 
            private float wheelRadius; 
            private float wheelZOffset; 
            private float wheelRestingFrac; 
            private float wheelDampingFrac; 
            private int wheelNumRays; 
            private float topSpeed;
            private float driveTorque; 
            private float gravity; 
     
            // control stuff 
            private float destSteering = 0.0f; // +1 for left, -1 for right 
            private float destAccelerate = 0.0f; // +1 for acc, -1 for brake 
             
            private float steering = 0.0f; 
            private float accelerate = 0.0f; 
            private float hBrake = 0.0f; 
            
            #endregion 
     
            /// On construction the physical/collision objects are created, but 
            /// not registered 
            public Car(bool FWDrive, bool RWDrive, float maxSteerAngle, float steerRate, float wheelFSideFriction, float wheelRSideFriction
                 float wheelFwdFriction, float wheelRwdFrictionfloat wheelTravel, float wheelRadius, float wheelZOffset, float wheelRestingFrac, 
                 float wheelDampingFrac, int wheelNumRays, float topSpeed, float driveTorque, float gravity) 
            { 
                this.fWDrive = FWDrive; 
                this.bWDrive = RWDrive; 
                this.maxSteerAngle = maxSteerAngle; 
                this.steerRate = steerRate; 
                this.wheelFSideFriction = wheelFSideFriction; 
                this.wheelRSideFriction = wheelRSideFriction; 
                this.wheelFwdFriction = wheelFwdFriction; 
                this.wheelRwdFriction = wheelRwdFriction; 
                this.wheelTravel = wheelTravel; 
                this.wheelRadius = wheelRadius; 
                this.wheelZOffset = wheelZOffset; 
                this.wheelRestingFrac = wheelRestingFrac; 
                this.wheelDampingFrac = wheelDampingFrac; 
                this.wheelNumRays = wheelNumRays; 
                this.topSpeed = topSpeed;
                this.driveTorque = driveTorque; 
                this.gravity = gravity; 
     
                chassis = new Chassis(this); 
     
                SetupDefaultWheels(); 
            } 
     
     

    More changes...
                wheels[(int)WheelId.WheelBR].Setup(this
                              BRPos, 
                              axis, 
                              spring, 
                              wheelTravel, 
                              inertia, 
                              wheelRadius, 
                              wheelRSideFriction, 
                              wheelRwdFriction, 
                              damping, 
                              wheelNumRays); 
     
                wheels[(int)WheelId.WheelFR].Setup(this
                              FRPos, 
                              axis, 
                              spring, 
                              wheelTravel, 
                              inertia, 
                              wheelRadius, 
                              wheelFSideFriction, 
                              wheelFwdFriction, 
                              damping, 
                              wheelNumRays); 
     
                wheels[(int)WheelId.WheelBL].Setup(this
                              BLPos, 
                              axis, 
                              spring, 
                              wheelTravel, 
                              inertia, 
                              wheelRadius, 
                              wheelRSideFriction, 
                              wheelRwdFriction, 
                              damping, 
                              wheelNumRays); 
     
                wheels[(int)WheelId.WheelFL].Setup(this
                              FLPos, 
                              axis, 
                              spring, 
                              wheelTravel, 
                              inertia, 
                              wheelRadius, 
                              wheelFSideFriction, 
                              wheelFwdFriction, 
                              damping, 
                              wheelNumRays); 
            } 

    and some more additions...

                wheels[(int)WheelId.WheelBL].Lock = (hBrake > 0.5f);  
                wheels[(int)WheelId.WheelBR].Lock = (hBrake > 0.5f);  
     
                wheels[(int)WheelId.WheelFL].MaxAngVel = topSpeed;  
                wheels[(int)WheelId.WheelFR].MaxAngVel = topSpeed;  
                wheels[(int)WheelId.WheelBL].MaxAngVel = topSpeed;  
                wheels[(int)WheelId.WheelBR].MaxAngVel = topSpeed;  
     
                if (hBrake > 0.5f)  
                {  
                    wheels[(int)WheelId.WheelBL].Side = 2f;  
                    wheels[(int)WheelId.WheelBR].Side = 2f;  
                }  
                else 
                {  
                    wheels[(int)WheelId.WheelBL].Side = this.wheelRSideFriction;  
                    wheels[(int)WheelId.WheelBR].Side = this.wheelRSideFriction;  
                }  

    I'll talk about the 2.0f later.

    Now for some similar changes in CarObject.cs
    namespace JiggleGame.PhysicObjects 
        class CarObject : PhysicObject 
        { 
     
            private Car car; 
            private Model wheel; 
     
            public CarObject(Game game, Model model,Model wheels, bool FWDrive, 
                           bool RWDrive, 
                           float maxSteerAngle, 
                           float steerRate, 
                           float wheelFSideFriction, 
                           float wheelRSideFriction, 
                           float wheelFwdFriction, 
                           float wheelRwdFriction, 
                           float wheelTravel, 
                           float wheelRadius, 
                           float wheelZOffset, 
                           float wheelRestingFrac, 
                           float wheelDampingFrac, 
                           int wheelNumRays, 
                           float topSpeed,
                           float driveTorque, 
                           float gravity) 
                : base(game, model) 
            { 
                car = new Car(FWDrive, RWDrive, maxSteerAngle, steerRate, 
                    wheelFSideFriction, wheelRSideFriction, wheelFwdFriction,    
                    wheelRwdFriction, wheelTravel, wheelRadius, 
                    wheelZOffset, wheelRestingFrac, wheelDampingFrac, 
                    wheelNumRays, topSpeed, driveTorque, gravity); 
     
                this.body = car.Chassis.Body; 
                this.collision = car.Chassis.Skin; 
                this.wheel = wheels; 
     
                SetCarMass(100.0f); 
            } 

    And at the top of Wheel.cs under 'private fields' 
            // things that change   
            private float angVel;  
            private float steerAngle;  
            private float torque;  
            private float driveTorque;  
            private float axisAngle;  
            private float displacement; // = mTravel when fully compressed  
            private float upSpeed; // speed relative to the car  
            private bool locked;  
            private float maxAngVel; 

    still in Wheel.cs

            public bool Lock  
            {  
                get { return locked; }  
                set { locked = value; }  
            }  
     
            public float Side  
            {  
                get { return sideFriction; }  
                set { sideFriction = value; }  
            }   
              
            public float MaxAngVel  
            {  
                get { return maxAngVel; }  
                set { maxAngVel = value; }  
            } 
    Also delete the line float maxAngVel = 300; in the Update() method.

    That should almost do it.  Get some speed then turn hard and press 'b' (or whatever you have it mapped to) to see the improved hand brake.   

    Adding Tuning Capabilities

    A bonus to all this work for the hand brake is you now have a lot more freedom to fine tune your car.  Instead of having to change friction of all four tires you can change the front and rear seperately to get a car that drifts or handles however you want.

    Open JiggleGame.cs and paste the following in place of the old variables
    carObject = new CarObject(this, carModel, wheelModel, truetrue, 30.0f, 5.0f, 3.6f, 2.6f, 
                    .5f, 1f, 0.3f, 0.4f, -0.10f, 0.5f, 
                    0.9f, 1, 250.0f, 400.0f, physicSystem.Gravity.Length()); 
    250.0f is the new top speed variable.  These settings should be a fun place to start.  You'll also notice that some of these settings give the car body roll which not only looks better but is more realistic. 

    3.6f is the front lateral friction and 2.6f is the rear.  These settings will make the rear slide out when taking a corner to fast.  If they are even the car will never spin out.  
    .5f is the front longitudinal (I think that's what it's called or acceleration, again, no college) friction and 1f is the rear.  Having a bigger number in the rear let's you keep a drift around corners.
    Both these settings are proportional between the front and rear so 4f in front and 3f in rear will handle pretty similar to 5f in front and 3.75f in rear.  Play with these till you get them where you want.  

    Now back to the 2.0f.  This adjusts the lateral friction everytime the hand brake is activated letting the rear end slide around.  Since it doesn't adjust the longitudinal friction the locked tires still create the same amount of drag as before.

    I would also suggest you change the gravity in PhysicsSystem.cs from -10 to -30
            public PhysicsSystem()  
            {  
                CurrentPhysicsSystem = this;  
                Gravity = -30.0f * Vector3.Up;  
            } 
    This will make the car and physics in general less like the moon and more like Earth.

    Next time I'll go into what all the CarObject settings do as well as a few new tweaks to the car class.  

    I hope this helps someone.
  • 20/04/2009 11:31 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    Interesting.
    nikescar:
    Next time I'll go into what all the CarObject settings do as well as a few new tweaks to the car class.

    Please do. Did you get to solve the problem where at high speed straight driving, the car starts wobbling left-and right, which causes some bad behavior?

  • 20/04/2009 11:33 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    Nice samples (but your changes don't appear in red).

    I spent half the day yesterday playing with the car class in JigLib and spent a few hours just working on drifting as it's one of the main features we want in our game.
    Retroburn Game Studios
    XBoxArt.com - Now includes box art from Community games, Arcade games and Retail 360 games!
  • 20/04/2009 11:45 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    I saw that some people were having trouble with that and there's a few different ways to fix it.  


    The setup I posted above should work fine though.  I think the variable that I changed to stop it from wobbling is the fwdFriction and rwdFriction.  It seems that if they are too far above 1f they cause a problem.  I wouldn't make them anymor than 1.5f or so.  

    @Martin
    I changed it to underlined.  For some reason in the code block you can't use red.  It shows up when I'm editing but not in the post.  

    Also, I emailed you the script.  Can't wait to hear a fine UK voice directing me around my rally stage.
  • 20/04/2009 12:05 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    Ooh, very nice! Drifting is my favorite thing to do in "real" racing games. Can you do my second favorite thing with that setup; donuts?
    "No programmer can pick up a TV remote without thinking what it would take to add a stun gun. [...] Their motto is 'if it ain't broke, it doesn't have enough features yet'" - Scott Adams, The Dilbert Principle

    The signature that was too big for the 512 char limit
  • 20/04/2009 12:16 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    You can tweak some of the settings to get some pretty lousy donuts but the way the car physics are written it's not that great.  I've looked into changing the slipVel variable around to make it more realistic but I'm not quite there yet.

    Believe me though, programming gods willing, I'll have a very realistic vehicle by the time my games released.  
  • 20/04/2009 12:20 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    One of the guys at my work (Alexis Drew) is a drift racing champion, he apparently holds some record for doing donuts too. I've not tried to do any in my game, but since I'm using only a slightly modified JigLib car class then probably can't do them very well.
    Retroburn Game Studios
    XBoxArt.com - Now includes box art from Community games, Arcade games and Retail 360 games!
  • 20/04/2009 12:35 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    This setup is a little more drift car like:
    carObject = new CarObject(this, carModel, wheelModel, truetrue, 30.0f, 5.0f, 3.6f, 3.0f, 
                    .5f, 1f, 0.20f, 0.4f, 0.05f, 0.5f, 
                    0.9f, 1, 250.0f, 400.0f, physicSystem.Gravity.Length()); 

    Keep in mind that you likely won't be able to keep a drift if you're using the keyboard.

    I saw a youtube video of a WRX STI breaking the "Most donuts in a minute record".  Pretty crazy stuff
  • 29/04/2009 15:26 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    I finally got some time to play with this. I've implemented your changes and it is very drifty! :-)

    One thing - is there an easy way to modify acceleration and top speed? It's really sluggish with this setup. I've tried modifying the torque and the wheel friction values, but nothing works well (although I got it to speed up really fast and then immediately flip and roll over when I turned slightly - hilarious!). How are you doing it?

    ...Too bad more people apparently aren't modifying this. When I get further along I'll post screens of what I'm using it for (hint: Streets of SimCity was one of my favorite games).
    "No programmer can pick up a TV remote without thinking what it would take to add a stun gun. [...] Their motto is 'if it ain't broke, it doesn't have enough features yet'" - Scott Adams, The Dilbert Principle

    The signature that was too big for the 512 char limit
  • 29/04/2009 19:00 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    This is something I've been working on between struggling with gamestate management.  I've updated the Hand Brake post to include a topSpeed variable.  Don't miss the part about the gravity. 

    Acceleration is another issue.  I'm having trouble getting this to work the way I want it.  I'm working on it though.

    I promised a commented out vehicle class and I am working on it.  I'd like to progress the class a little further first though. 
  • 29/04/2009 19:17 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    But what does MaxAngVel do? Did you forget some code? ;-)

    ..I'm looking forward to your completed vehicle class. That should be very useful to a lot of people!
    "No programmer can pick up a TV remote without thinking what it would take to add a stun gun. [...] Their motto is 'if it ain't broke, it doesn't have enough features yet'" - Scott Adams, The Dilbert Principle

    The signature that was too big for the 512 char limit
  • 29/04/2009 21:26 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    Oops.  I guess I should have tried my tutorial from scratch.  maxAngVel is already used in Wheels.cs in Update().  You need to delete the line float maxAngVel = 200;.  I updated the post.  


  • 29/04/2009 22:56 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    Hmm, for those wanting to make a semi-arcadey drifting game with most of it's roots in physics I may have good news.  I was looking around the code a bit and I might have a gameplan figured out.  This would let the car go past it's current slip threshold (like it does with my code changes) to a certain angle and then hold at a second threshold (unless you push it too hard) allowing for some massive high speed drifts.  

    I'm not ready to work on this just yet but it is something I have planned for the future.  I wish I had this programming stuff down because the logic isn't as complicated to me.
  • 30/04/2009 0:50 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    That'd be great! Just this afternoon I had added XmlParticles to the JigLibX-NetworkStateManagement concoction I have now, so I could have smoke when the car skids. However I wasn't sure where to put it... Physics like this was never my strong suit.

    If you can get some pseudocode down, I can turn it into real code if you like. :-)
    "No programmer can pick up a TV remote without thinking what it would take to add a stun gun. [...] Their motto is 'if it ain't broke, it doesn't have enough features yet'" - Scott Adams, The Dilbert Principle

    The signature that was too big for the 512 char limit
  • 30/04/2009 2:35 In reply to

    Adding a Wheel Skid Event

    Physics may or may not be my strong suit.  I'm still trying to figure that out.

    For adding smoke when the car skid you have to know when the tires are skidding (I know, obvious).  You do that in the Wheel.cs.

    Add to the fields:
    private bool wheelSkid; 
      
    Change this:
        if ((fwdVel > slipVel) || (fwdVel < -slipVel)) 
                    friction *= slipFactor; 
                else 
                    if ((fwdVel > noslipVel) || (fwdVel < -noslipVel)) 
                        friction *= 1.0f - (1.0f - slipFactor) * (System.Math.Abs(fwdVel) - noslipVel) / (slipVel - noslipVel); 

    To this:
                if ((sideVel > slipVel) || (sideVel < -slipVel)) 
                { 
                    friction *= slipFactor; 
                    wheelSkid = true
                } 
                else 
                { 
                    wheelSkid = false
                    if ((sideVel > noslipVel) || (sideVel < -noslipVel)) 
                        friction *= 1.0f - (1.0f - slipFactor) * (System.Math.Abs(sideVel) - noslipVel) / (slipVel - noslipVel); 
                } 

    Add near the other returns at the end of the class:
            public bool WheelSkid 
            { 
                get { return wheelSkid; } 
            } 

    Now in the Car.cs add:
    private bool skid; 

    and add this in the PostPhysics method:
                if (wheels[(int)WheelId.WheelFL].WheelSkid | wheels[(int)WheelId.WheelFR].WheelSkid | 
                    wheels[(int)WheelId.WheelBL].WheelSkid | wheels[(int)WheelId.WheelBR].WheelSkid) 
                { 
                    skid = true
                } 
                else skid = false

    You can pick whichever wheels you want to create smoke when a skid occurs, like the rear only for instance.

    then add a return with the rest of the returns:
            public bool Skid 
            { 
                get { return skid; } 
            } 

    You would then check for skid=true by calling carObject.Car.Skid and telling the emitter to initialize.

    Not surprisingly this is some of the code that I want to play with for some drifting.  I'll give the drifting code a whirl tomorrow and let you know.  Now I should really concentrate on some 3D modelling tutorials.

    Maybe you could help me with something.  I have a dust emitter that right now is centered on my car object.  I would like to have the dust originate from the rear of the car though.  I haven't really looked into matrices too much but I'm pretty sure I would have to do some kind of multiplication of the two matrices.  The dust emitter would essentially rotate around the center of the car at a certain distance while keeping at the rear of the car, following the orientation.  Not sure if that makes sense.
  • 30/04/2009 7:36 In reply to

    Get Some Basic Drifting

    Huge breakthrough!  I was bumping around in Wheel.cs doing trial and error modifications of different variables so I could come up with a drifting mod when I stumbled upon the answer.  

    A variable named smallVel is the key.  It applies a force somewhere between the drive force and the side force.  Right now it should be set to 3, change it to 20 and give your car a try.  With my settings for the car it's like driving on ice but controlled and super fun for drifting.  Since my game is a rally racer and I planned on having only dirt tracks, I toned it down to 12.  This gave me a very authentic feel as well as taking care of some other small issues I had with the handling.  Now I'll be able to have pavement, dirt and snow surfaces and it'll be easy to modify the class to fit those surfaces. 

    This class is almost where I want it.  A couple more small features, a lot of cleanup and then I'll start getting the class ready to post.  I don't know if it's the beer or what but I'm super psyched.  You should be able to turn this class into any type of racer.  Onroad, offroad, even arcadey with a bit of physics.

    edit:

    Make the following change so that the car doesn't slide around when stopped.  Replace float smallVel = 3; with this chunk of code:
                float smallVel; 
                if (angVel == 0 & !locked) 
                { 
                    smallVel = 1; 
                } 
                else smallVel = 12; // Or 20 or whatever you want, play with it

  • 01/05/2009 13:52 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    nikescar:
    Maybe you could help me with something.  I have a dust emitter that right now is centered on my car object.  I would like to have the dust originate from the rear of the car though.  I haven't really looked into matrices too much but I'm pretty sure I would have to do some kind of multiplication of the two matrices.  The dust emitter would essentially rotate around the center of the car at a certain distance while keeping at the rear of the car, following the orientation.  Not sure if that makes sense.

    Yes, that makes sense. It's not that difficult at all. You want to take the rotation of the car, and move your pivot point x distance behind the car. I'm not sure if the car object uses Vector3s or matrices for rotation - I'll look at the code and post when I have it working. (I'm using the positions of the rear tires for particle effects so I hadn't needed to do this yet).

    BTW, I think you had edited your post to add this in? I'm pretty sure I didn't see it the first time I read your response. It's really better to add a new post, since I had no way of knowing anything had changed and just now came back in here to look at your code again. Or I could be completely wrong and misremembering things...
    "No programmer can pick up a TV remote without thinking what it would take to add a stun gun. [...] Their motto is 'if it ain't broke, it doesn't have enough features yet'" - Scott Adams, The Dilbert Principle

    The signature that was too big for the 512 char limit
  • 01/05/2009 14:59 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    Alright, here you go:

    Vector3 OffsetAmount = new Vector3(0, 0, -3); 
     
    Vector3 OffsetPosition = pCar.carObject.Car.Chassis.Body.Position + 
        (pCar.carObject.Car.Chassis.Body.Orientation.Right * OffsetAmount.Z) + 
        (pCar.carObject.Car.Chassis.Body.Orientation.Up * OffsetAmount.Y) - 
        (pCar.carObject.Car.Chassis.Body.Orientation.Forward * OffsetAmount.X); 
     
    ParticleComponent.smokeParticles.AddParticle(OffsetPosition, Vector3.Zero); 

    The code should be pretty self explanatory. pCar is an instance of my PlayerCar object, which is basically a wrapper for CarObject that adds high level functionality specific to my game, such as score, network data, weapons, etc. OffsetAmount is a Vector3 that is the relative offset you want, in this case 3 units behind of the center of the car. OffsetPosition is the final, global, relative position, that you can then pass into your particle system or something. It took some trial and error to get all of these working correctly, but I've tested it in several positions and it seems to work OK. And the last line tells my ParticleComponent to add a particle at the specified position and initial velocity - replace it with your own particle code to get a nice stream of particles behind your car.

    Hope this helps!
    "No programmer can pick up a TV remote without thinking what it would take to add a stun gun. [...] Their motto is 'if it ain't broke, it doesn't have enough features yet'" - Scott Adams, The Dilbert Principle

    The signature that was too big for the 512 char limit
  • 01/05/2009 17:09 In reply to

    Re: Proper Hand Brake and Adding Tuning Capabilities

    Ya, I did edit it.  I think I edited it an hour or two after my original post.  I was a bit tired and I had a couple drinks.  ;p

    Thanks that code works perfectly for the dust emitter and I only had to add a little to fit my exhaust emitter.
Page 1 of 3 (60 items) 1 2 3 Next > Previous Next