May 23, 2012, 01:04:10 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Please report any bugs or issues that you might be encountering with the Beta in the Support System so that we can better keep track of any oustanding issues that may come up.

GameCore Support System
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Brake lights  (Read 648 times)
Spaz
Full Member
***
Posts: 109


View Profile
« on: May 06, 2009, 06:49:38 PM »

I've assigned different materials to the tail lights on my cars, and I can change the luminosity of them to make it look like the brake lights are on or off.  What I don't know how to do is activate the brake lights when the cars are slowing down.  I'd like to have it automatically happen for cars using the traffic system, and I'd also like to have it happen on a car I'm controlling when the forward arrow has been released and when the back arrow is pressed.

Anybody have an idea where in the new vehicle script I should be putting my code?  I really don't understand much of the movement code in the new scripts.

Thanks
« Last Edit: May 07, 2009, 10:23:17 AM by Spaz » Logged
Ron
Sr. Member
****
Posts: 326


View Profile
« Reply #1 on: May 06, 2009, 07:29:21 PM »

Here is what I have for the player... have not ventured into the traffic system yet though.

You may already have your 3d model named, if not, add a name in your opr file

Code:
OPRP

LoadObject Truck.obj
ObjectName CarBody
...
...
EditSurface rlights
SurfaceBlendMode Normal
SurfaceBlendOperation Add
SurfaceDiffuseMap turn3.jpg
SurfaceNormalMap
SurfaceSpecularMap
SurfaceDetailMap
SurfaceShaderSpec
SurfaceShaderEnabled 1
SurfaceFlags
SurfaceTextureFlags
SurfaceSpecular 0
SurfaceShinyness 128
SurfaceDetailAmount 0
SurfaceDetailMapScale 1
SurfaceTextureAnimLayers 1
SurfaceTextureScale 0 1.000000 1.000000
SurfaceTextureOffset 0 0.000000 0.000000
SurfaceTextureAnim 0 0.000000 0.000000
SurfaceTextureStep 0 0.000000 0.000000
SurfaceWaveParams 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
SurfaceNormalMapScale 1
SurfaceDisplacement 0
SurfaceNormalOffset 0
SurfaceNormalMapIntensity 1
SurfaceLuminosity 0
SurfaceDiffuse 1
SurfaceTransparency 0
SurfaceTranslucency 0
SurfaceColor 255 255 255
SurfaceDrawOrder 0
SurfaceNoDebugOverride 0
SurfaceAlphaTestThreshold 127

Then control it from the script.
Code:
if (handbrakePressed > 0.1f && gear != -1)
{
GetGameManager().GetWorld().GetObject("VehicleBody").GetMesh("CarBody").GetSurface("rlights").SetColor(1.25, 0.0, 0.0);
if (!aicontrolled && lightson)
{
GetGameManager().GetWorld().GetObject("VehicleBody").GetLight("LeftTailLightGround").SetIntensity( 0.03);
GetGameManager().GetWorld().GetObject("VehicleBody").GetLight("RightTailLightGround").SetIntensity( 0.03);
}
}
else
{
GetGameManager().GetWorld().GetObject("VehicleBody").GetMesh("CarBody").GetSurface("rlights").SetColor(0.7, 0.0, 0.0);
if (!aicontrolled && lightson)
{
GetGameManager().GetWorld().GetObject("VehicleBody").GetLight("LeftTailLightGround").SetIntensity( 0.015);
GetGameManager().GetWorld().GetObject("VehicleBody").GetLight("RightTailLightGround").SetIntensity( 0.015);
}
}

Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #2 on: May 07, 2009, 08:10:22 AM »

dang, I was think?ng of just this thing last night and I want to turn on break lights as soon as i press BACK (S) with racer demo Smiley
Logged
Spaz
Full Member
***
Posts: 109


View Profile
« Reply #3 on: May 07, 2009, 10:51:42 AM »

Thanks, Ron.  That's kind of how I have the headlights working as they switch from off, to dim, to bright when I press the "L" key.  I'd like the brake lights to be a little more automatic, though, so that whenever you let off the gas they come on dimly, and whenever you press the back arrow they come on bright until your speed becomes negative, at which point the reverse lights come on.  The scripting for the forward and back arrows confuses me, though, so I'm not sure where to put in the scripting for the tail lights.  Any ideas?
Logged
Spaz
Full Member
***
Posts: 109


View Profile
« Reply #4 on: May 07, 2009, 12:14:18 PM »

Well, I found where the code goes for the user-operated car.  The code below only controls brake lights because my model doesn't have any reverse lights yet.  Even if it did I'd still need to put in something to change the brake lights to reverse lights when the velocity went negative.

Code:
if (leftSideForce <= 0)
{
if (forwardVelocity < -DIRECTION_SWITCH_VELOCITY)
{
brakeEffectiveness = BRAKE_EFFECTIVENESS;
leftSideForce = 0;
}
else
                {
leftSideForce *= FORWARD_FORCE;
                   
                    TAILLIGHT_MODE = 0;
                    object.GetMesh("VehicleBody").GetSurface("TailLights").SetLuminosity(0.0);
               
                }
}
else
{
if (forwardVelocity > DIRECTION_SWITCH_VELOCITY)
{
brakeEffectiveness = BRAKE_EFFECTIVENESS;
leftSideForce = 0;
}
else
                {
leftSideForce *= BACKWARD_FORCE;
                   
                    TAILLIGHT_MODE = 1;
                    object.GetMesh("VehicleBody").GetSurface("TailLights").SetLuminosity(1.0);
                }
}

I'll keep searching for where it goes on the automatically spawned traffic system vehicles and post that when I get it figured out.  If anyone can beat me to it, though, please show me how! Smiley
« Last Edit: May 07, 2009, 12:56:03 PM by Spaz » Logged
Spaz
Full Member
***
Posts: 109


View Profile
« Reply #5 on: May 07, 2009, 01:10:32 PM »

OK, now I've got traffic spawned by the traffic system that has brake lights that show up when they slow down for another car.  This is around line 900 or so in the new vehicle script.  I've dinked with the script quite a bit, though, so look around a little bit if you don't see it in your script right away.

Code:
if (pathSpeed >= 0 && forwardVelocity >= pathSpeed)
{
stopped = true;                   
}
else
{
forward = PATH_SPEED_MULTIPLIER;
stopped = false;
                   
                    //Activate brake lights
                    TAILLIGHT_MODE = 1;
                    object.GetMesh("VehicleBody").GetSurface("TailLights").SetLuminosity(1.0);
                   
waypointMove = startPos - waypointInfo.destination;
waypointMove.Normalize();

// are we turning left or right
float turnAngle = mtx.XAxis.DotProduct( waypointMove);
turnAngle = clamp( turnAngle * PATH_TURN_SHARPNESS, -1, 1);

The following three lines are the only ones I added:
    //Activate brake lights
    TAILLIGHT_MODE = 1;
    object.GetMesh("VehicleBody").GetSurface("TailLights").SetLuminosity(1.0);

Hope that helps some of you. Smiley
Logged
gekido
Guest
« Reply #6 on: May 20, 2009, 12:48:22 PM »

Objects handled by the traffic system are no different than normal objects - same goes for ones spawned via the terrain spawner system.  Just an FYI ;}
Logged
Pages: [1]
  Print  
 
Jump to:  

 
Powered by MySQL Powered by PHP bluBlur Skin © 2006, hbSkins
Powered by SMF 1.1.14 | SMF © 2006-2011, Simple Machines LLC
Valid XHTML 1.0! Valid CSS!