PDA

View Full Version : Havoc and car problems


mdoyle
01-19-2005, 12:18 PM
hi,

Wondering if anyone can help. I seem have a problem with my raycast car behaviour
in shockwave (the car was modeled in lightwave)

I seem to be able to get the suspension working but when I try to move the wheel positions don't update properly and seem to be dragging behind the car. The car was setup with the wheels as seperate objects and the pivot points where made at the centre of each part. So i have 4 seperate wheels parented to the body.

Cheers

M

MentalFish
01-19-2005, 02:15 PM
I have made a raycast car myself once, and the wheels was behaving as they should. I think I had a problem once when I updated the wheel models at the wrong point (on enterFrame instead of exitFrame, not sure though).

I'll dig out the code for my raycast car and post it here.

In the mean time I have this code available, which isnt based on raycasting but on sphere proxies working as wheels, with linear dashpots for springs:

property scene, havok, bodyHav, bodyMod
property localDown, localForward
property topSpeed, groundContact, wheelMass, powerCoeff
on beginSprite me
scene = member( "BlankScene" )
havok = member( "BlankHavok" )
scene.resetWorld()
havok.initialize(scene, 0.1, 1)
havok.gravity = vector(0,-9.81,0)
-- Set up properties
localForward = vector(0,0,1)
localDown = vector(0,-1,0)
topSpeed = 100
-- create ground
groundRes = scene.newModelResource("GroundPlaneRes", #box)
groundRes.width = 150
groundRes.length = 150
groundRes.height = 1
groundMod = scene.newModel("ground", groundRes)
groundMod.transform.rotation = vector(-10,-10,0)
groundMod.transform.position = vector(0,-20,0)
groundMod.addModifier(#meshdeform)
groundHav = havok.makeFixedRigidBody(groundMod.name)
groundHav.friction = 1
groundHav.restitution = 1
-- point camera
sceneCam = scene.camera[1]
sceneCam.transform.position = vector(40,40,80)
sceneCam.pointat(groundMod.transform.position, -localDown)
-- Create car body
bodyRes = scene.newModelResource("body", #box)
bodyRes.height = 0.1
bodyRes.width = 2
bodyRes.length = 4
bodyMod = scene.newModel("body", bodyRes)
bodyMod.transform.position = vector(0, 20, 0)
bodyMod.transform.rotation = vector(0,0,0)
bodyMod.addModifier(#meshdeform)
bodyHav = havok.makeMovableRigidBody(bodyMod.name, 4.0)
bodyHav.friction = 0.5
bodyHav.restitution = 0
-- Seting up dummy-wheels
wheelRes = scene.newModelResource("wheel", #sphere)
wheelRes.radius = 0.5
wheelBase = 2.5
axleWidth = 1.5
springStrength = 16
springDamping = 0.8
wheelMass = 10.0
wheelPos=[vector(-axleWidth/2, 0, -wheelBase/2), \
vector(-axleWidth/2,0, wheelBase/2), \
vector(axleWidth/2, 0, -wheelBase/2), \
vector(axleWidth/2, 0, wheelBase/2)]
repeat with n=1 to 4 then
-- Make dummies / sphere wheels
wheelMod = scene.newModel("wheel" & n, wheelRes)
wheelMod.transform.position = wheelPos[n] + vector(0,18.0,0) --Displaced to car's body
wheelMod.addModifier(#meshdeform)
wheelHav = havok.makeMovableRigidBody(wheelMod.name, wheelMass)
-- Set up dampers
linDashpot = havok.makeLinearDashpot("linDP" & n, "body", "wheel" & n)
linDashpot.strength = springStrength
linDashpot.pointA = wheelPos[n] - vector(0,1,0)
linDashpot.damping = springDamping
-- Disable rotation of spheres so when friction is applied to them, the car brakes
angDashpot = havok.makeAngularDashpot("angDP" & n, "wheel" & n)
angDashpot.strength = 1
angDashpot.damping = 1
havok.registerInterest( "wheel" & n, "ground", 0, 0, #collisionHandler, me )
end repeat
groundContact = [0,0,0,0]
powerCoeff = 0
end

on collisionHandler(me, collisionDetails)
repeat with n = 1 to 4 then
if collisionDetails[1] = "wheel" & n then
groundContact[n] = 1
end if
end repeat
end

on exitFrame(me)
-- Retrieve and set up car state
tempTrans = bodyMod.transform.duplicate()
tempTrans.position = Vector(0,0,0)
tempTrans.scale = Vector(1,1,1)
worldForward = tempTrans * localForward
worldAxis = tempTrans * -localDown
worldRight = worldForward.cross(worldAxis)
worldForward.normalize()
worldAxis.normalize()
worldRight.normalize()
currentVel = bodyHav.linearVelocity
currentSpeed = currentVel.dot(worldForward)
propSpeed = min(abs(currentSpeed) / topSpeed , 1)
angularVel = bodyHav.angularVelocity
roadGrip = 1-(abs(currentSpeed/topSpeed))
slideSpeed = worldRight.dot(currentVel)
tempPowerCoeff = (groundContact[1] + groundContact[2] + groundContact[3] + groundContact[4])/4.0
if tempPowerCoeff > powerCoeff then
powerCoeff = powerCoeff + 0.1
else if tempPowerCoeff < powerCoeff then
powerCoeff = powerCoeff - 0.1
end if
-- Prevent side slipping and spinning
linImp = worldRight * (-slideSpeed * bodyHav.mass * roadGrip) * powerCoeff
angImp = worldAxis * angularVel.dot(worldAxis) * (-roadGrip * wheelMass) * powerCoeff
repeat with n = 1 to 4 then
if groundContact[n] = 1 then
havok.rigidBody("wheel" & n).applyImpulse( linImp )
havok.rigidBody("wheel" & n).applyAngularImpulse( angImp )
end if
end repeat
-- Going forward
if keyPressed(126) then
if groundContact[1] = 1 then
havok.rigidBody("wheel1").applyImpulse( worldForward * 10 )
end if
if groundContact[3] = 1 then
havok.rigidBody("wheel3").applyImpulse( worldForward * 10 )
end if
end if
-- Braking
if keyPressed(125) then
havok.rigidBody("wheel1").friction = 0.5
havok.rigidBody("wheel2").friction = 0.3
havok.rigidBody("wheel3").friction = 0.5
havok.rigidBody("wheel4").friction = 0.3
else -- Rolling resistance
havok.rigidBody("wheel1").friction = 0.2
havok.rigidBody("wheel2").friction = 0.2
havok.rigidBody("wheel3").friction = 0.2
havok.rigidBody("wheel4").friction = 0.2
end if
-- Going right
if keyPressed(124) then
dir = 1
else if keyPressed(123) then -- Going left
dir = -1
else -- Going forward
dir = 0
end if
-- Define front wheels
wheels = [4,2]
repeat with n=1 to 2 then
--if groundContact[wheels[n]] = 1 then
havok.rigidBody("wheel" & wheels[n]).applyImpulse(worldRight * dir * (1-roadGrip)* 20 * powerCoeff)
--end if
end repeat
groundContact = [0,0,0,0]
havok.step(0.0333, 4)
go the frame
end

mdoyle
01-20-2005, 04:36 AM
Thanks very much for your help. You were totally right, I was updating the wheels on exit frame instead of enter frame. Thanks for your code for the spring stuff could come in handy. If you can dig out the code for your car that would be brilliant just to compare and I appreciate it alot.

Again thanks, was spending almost 2 days on that and I couldn't work it out.

Cheers

M

wowens
01-23-2005, 10:00 PM
petterms -- If it isn't too much trouble, I would also like a copy of your raycast code. I am having the same problem as mdoyle.

MentalFish
01-24-2005, 03:42 AM
Sorry, I forgot about it :rolleyes:

Here comes the Director file. One thing to note is that I had to rotate the model on setup, so Z becomes the up axis instead of Y.

mdoyle
02-03-2005, 06:09 AM
Thanks for the code patterns. Gave it to the programmer (sorry if I am not technical here I mainly do the 3d and the programmer does most of the scripting)

He has managed to get it working with a plain world etc but I have a few questions to see if you might be able to answer them.

First of all your car is in the w3d that is getting used, have you found from experience that using cars from seperate w3d's can cause problems? As there will be a car chooser in mine and wasn't sure if there is problems.

Secondly my map is slightly more complicated and there will be lots going on, But just now my problem is that I am getting collisions from objects that are not there. For example i have cut out the road shape into a larger poly that is completely flat and given it a different shader. Now when I drive I am coliding with what seems to be invisible polys. If I a make a completely flat world grided I have no problems but if I start putting shape in and curves for roads I get colissions. After going over it for a few days I think its because of the the way the polys are lying but I don't really know.

I have attached an exe with w3d so you can run and see the problems I am getting with the car. If you make your way to the road and try and drive round it you will hit "something". I have also attached the model of the road so you can have a look at the model (and the car which is used). The programmer just now is trying to work out why this is happening but I am wondering if using my mesh and car then would you get the same problems?

Thanks for your help, I really appreciate any input you have given so far.

mdoyle
02-03-2005, 06:12 AM
attachment never worked :D Dunno why not cos it uploads. Its 7 megs cos of the exe so I think it was a bit big. He is going to try and make a physics proxy as well as a raycast proxy in the mean time to try and fix it. But I dunno if its my model, and if it is I can't work out why.


If you are too busy to look at it then cool, but I am unsure as to where the problems are lying.

Thanks for your time

mdoyle
02-03-2005, 09:34 AM
LOL After a day and a half re makin models and tryin different ways to fix it, it seems that the problem is that my car was using box detect type. If I change it to concave I don't get the problems with with hitting invisible objects.

I am wondering if that has ever happened to you, and whether I should be able to use a box as a detect and if its the way I am parenting the wheels and setup of the car?

MentalFish
02-04-2005, 03:23 PM
Hi again. Yes, when you mention it, i did have some issues with the convex/concave settings of Havok.

So you are up and running now?

MentalFish
02-04-2005, 03:32 PM
By the way, I don't think you should parent the wheels to the body, they should be placed by code only. You might get some problems because of that parenting. On the issue of box detect, i think you should use concave (isConvex = false) :

pCarModel = pW3D.model(pCarName)
pCarModel.addModifier(#meshdeform)
pRigidBodyCar = pHavok.makeMovableRigidBody(pCarName, pCarMass, false)

mdoyle
02-07-2005, 04:38 AM
Yeah, we tried to stay away from the concave at first to keep the amount of calculations lower, but in the end it obviously was causing problems. Because basically I am the designer and do most of the 3d stuff and only know a little of lingo, there is always a bit of delay in creating shockwave stuff, cos its kind of trial and error. If I built something and it doesn't work str8 away we are trying to work out if its the code or the setup in lightwave. Its really the first racing kind of game we are doing since before it was mainly walk throughs and character stuff. The parenting of the wheels was done so the programmer had the position of the wheels in the right place, but then he does place them afterwards in code so I am hoping that won't affect too much.

I had a look at your reflection tests and you architecture walkthru things which I quite liked. Being a designer mainly I have been trying to get reflections set up like you have done. Will try and do some tests with the programmer this week but was wondering if you had any pointers before I started.

In your car reflection I noticed that you had a texture map as well as a reflection map, but when I tried that before it seemed to blend out the original texture maps with reflection. Also was wondering if it was a well made reflection map in your architecture room or is it just deceptive in how it works?

Cheers

Marky

MentalFish
02-07-2005, 04:54 AM
The reflection map of the car uses blend mode. This code sets the texture in texture layer 2 to 15% visible:
member("scene").shader("myShader").blendFunctionList[2] = #blend
member("scene").shader("myShader").blendSourceList[2] = #constant
member("scene").shader("myShader").blendConstantList[2] = 15

The reflection on the floor is just a duplicate mirror of the original model (with a transparent floor). The same with the reflective car demo I made, alpha in the texture of the road, with a mirror car underneath it.

mdoyle
02-07-2005, 04:58 AM
Thats what we were thinking it could be, but think that would be to processer intensive to create that. Thanks for the quick reply and again sharing your code. I will post once it is taking a wee bit more shape as its going to be a fairly detail map and will have the task of trying to get the game working on a low enough spec pc with the amount of polys and textures.

If you ever need help in testing or creating assets for your own shockwave stuff then please don't hesitate to ask as you have been very helpful so far and I appreciate it greatly

wowens
03-30-2005, 09:07 AM
I'm having a slight problem with the "raycast.dir" Director file and the model configuration in LightWave. Does anyone have a sample LightWave model that shows the correct relationship between the vehicle's body and wheels? I'm able to import the W3D file into Director. However, the vehicle's body rests on the terrain and the wheels are located away from the body. Also, the arrow keys do not have any affect on the vehicle. How large should the model be in LightWave? Any assistance would be greatly appreciated.

MentalFish
04-19-2005, 04:09 AM
For the raycast car to work, you need to rotate the whole scene so the z-axis is the up axis. It is messy I know, so I will propose a simpler solution soon, not using raycasting at all.

wowens
04-21-2005, 09:11 AM
petterms -- I was able to import and apply the "raycast" scripts to the LightWave model in Director. I found the information on your Web site. The key is the scale of the models in LightWave -- I originally built the models to scale in LightWave.

So following your formula -- "The scale difference between LightWave and Shockwave is 1:100. This means 1 meter in LightWave is 100 units in Shockwave." -- I scaled my LightWave models to 1% of their original size. I then exported the scene to the Shochwave W3D format.

The only problem I've encountered is the vehicle slowly rolls backwards without pressing any keys. I tried applying a little "friction" and "restitution" to the terrain, but that didn't seem to help. Currently, the terrain is a simple flat plane with a grass texture.

Any lighting tips would also be appreciated.

MentalFish
04-21-2005, 04:22 PM
I dont think the raycast script as I made it has any rolling resistance. It has to be scripted somehow, and I dont have an immediate answer I am afraid. The principle of the raycast script is that the car hovers obove the ground like a hovercraft and the drivability of it is scripted in (no regular havok friction to steer the car)

That will change with the dashpot car I am making now, its much easier to script and understand what is going on. Will post as soon as something is ready for testing.