Share with us how are you using the powerrrr of the force
Moderator: Alain
by Leadwerks » Mon May 18, 2009 9:57 am
I am getting really good results with this. I might have been testing an earlier version before. Here's what I found:
-Use values of springConstant=70.0 and springDamper=5.0
-The suspension length should be somewhere around the tire radius*0.5.
-Wheels rotate around the z axis. (It would be nice if this could be changed.)
-The matrix argument in the creation command doesn't appear to do anything, but you must pass an identity matrix to it.
-Use GetTireMatrix() to visualize the tires.
-Use the number of tires you specify in the creation command. Any fewer will cause errors. (I think this constraint should be removed.)
Here are the results:
http://www.youtube.com/watch?v=jq2Qp3uFyZwThanks to Dave for making such a great vehicle for Newton users.
Last edited by
Leadwerks on Mon May 18, 2009 10:58 am, edited 2 times in total.
-
Leadwerks
-
- Posts: 569
- Joined: Fri Oct 27, 2006 2:54 pm
by Julio Jerez » Mon May 18, 2009 10:25 am
Haa you see.
It is all about trying to geting to work.
The good thing of this car solution is eh it does not slow down in any cituation and it is very robust, and very stable
I am glad you get going, some how it look like cars is the Holly Grail for Graphics Engines that integrate a third party Physics engine, and now you have your solution.
beside the setting you came across, if you trye small deviation, they lead to very interesting car configuations.
Very, very cool
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Leadwerks » Tue May 19, 2009 2:46 pm
Here are some things I think would help make it better:
-Return the speed or omega of a tire, to calculate engine RPMs and engine sound pitch.
-Align the tires to any direction.
-Return the normal of the ground a tire hits.
-Pick filter callback so the tires don't have to collide with everything, or the chassis OnAABBOverlapDo() callback could be used to tell if an object is collidable with the tire.
-
Leadwerks
-
- Posts: 569
- Joined: Fri Oct 27, 2006 2:54 pm
by Sury » Fri May 29, 2009 1:37 pm
That was very nice!
-
Sury
-
- Posts: 193
- Joined: Sat Aug 14, 2004 5:32 am
- Location: Bulgaria
by Leadwerks » Mon Jun 01, 2009 5:56 pm
This is my source code for the vehicle, if you are interested:
- Code: Select all
Type TVehicle Extends TJoint {expose}
Method Free()
If newtonJoint
DGRaycastVehicleDestroy(newtonJoint)
newtonJoint=Null
EndIf
Super.free()
EndMethod
Method lua_AddTire:Int(x#,y#,z#,radius:Float=0.5,width:Float=0.1,mass:Float=1.0,friction:Float=1.0,suspensionLength:Float=0.0,springConstant:Float=70.0,springDamper:Float=5.0) {rename="AddTire"}
Return addtire([x,y,z],radius,width,mass,friction,suspensionLength,springConstant,springDamper)
EndMethod
Method AddTire:Int(position:Byte Ptr,radius:Float=0.5,width:Float=0.1,mass:Float=1.0,friction:Float=1.0,suspensionLength:Float=0.0,springConstant:Float=70.0,springDamper:Float=5.0) {rename="AddTire_"}
Const castmode:Int=1
If suspensionLength=0.0 suspensionLength=radius*0.5
DGRaycastVehicleAddTire(newtonjoint,Null,position,mass,radius,width,friction,suspensionLength,springConstant,springDamper,castmode)
Return CountTires()-1
EndMethod
Method CountTires:Int()
Return DGRaycastVehicleGetTiresCount(newtonjoint)
EndMethod
Method SetTorque(torque:Float,tire:Int=-1)
If torque<>0.0 parent.unfreeze()
If tire=-1
For tire=0 To CountTires()-1
DGRaycastVehicleSetCustomTireTorque(newtonjoint,tire,torque)
Next
Else
DGRaycastVehicleSetCustomTireTorque(newtonjoint,tire,torque)
EndIf
EndMethod
Method SetBrake(brake:Float,tire:Int=-1)
If brake<>0.0 parent.unfreeze()
If tire=-1
For tire=0 To CountTires()-1
If Not IsAirborne(tire)
DGRaycastVehicleSetCustomTireBrake(newtonjoint,tire,brake)
EndIf
Next
Else
If Not IsAirborne(tire)
DGRaycastVehicleSetCustomTireBrake(newtonjoint,tire,brake)
EndIf
EndIf
EndMethod
Method SetSteerAngle(angle:Float,tire:Int=-1)
If tire=-1
For tire=0 To Min(1,CountTires()-1)
DGRaycastVehicleSetCustomTireSteerAngleForce(newtonjoint,tire,Radians(angle),1)
Next
Else
DGRaycastVehicleSetCustomTireSteerAngleForce(newtonjoint,tire,Radians(angle),1)
EndIf
EndMethod
Method GetSpeed:Float(tire:Int=-1)
Return DGRaycastVehicleGetSpeed(newtonJoint)
EndMethod
Method IsAirborne:Int(tire:Int=-1)
If tire>-1
Return Not DGRaycastVehicleGetTireOnAir(newtonJoint,tire)
Else
Return Not DGRaycastVehicleGetVehicleOnAir(newtonJoint)
EndIf
EndMethod
Method GetTireMatrix:TMat4(tire:Int)
Local mat:TMat4=New TMat4
DGRayCarTireMatrix(newtonjoint,tire,mat)
Local quat:TQuat=mat.rotation()
Local pos:TVec3=mat.translation()
newtonbodygetmatrix(parent.newtonbody,mat)
pos=TFormPointm(pos,Null,mat)
quat=TFormQuatm(quat,Null,mat)
pos=TFormPoint(pos,parent,Null)
quat=TFormQuat(quat,parent,Null)
mat=TMat4.fromrotation(quat)
mat.tx=pos.x
mat.ty=pos.y
mat.tz=pos.z
Return mat
EndMethod
Function Create:TVehicle(chassis:TBody,tires:Int=4)
Local vehicle:TVehicle
If Not InitJointLibrary() Return Null
vehicle=New TVehicle
vehicle.parent=chassis
vehicle.newtonjoint=DGRaycastVehicleCreate(tires,TMat4.identity(),chassis.newtonbody)
vehicle.connectlinks()
Return vehicle
EndFunction
EndType
Rem
bbdoc:Creates a new vehicle joint
EndRem
Function CreateVehicle:TVehicle(chassis:TBody,tires:Int=4)
Return TVehicle.Create(chassis,tires)
EndFunction
Rem
bbdoc:Creates a new vehicle joint
EndRem
Function AddVehicleTire:Int(vehicle:TVehicle,position:Byte Ptr,radius:Float=0.5,width:Float=0.1,mass:Float=1.0,friction:Float=1.0,suspensionLength:Float=0.0,springConstant:Float=70.0,springDamper:Float=5.0)
Return vehicle.addtire(position,radius,width,mass,friction,suspensionLength,springConstant,springDamper)
EndFunction
Rem
bbdoc:Adds torque to a tire
EndRem
Function SetVehicleTorque(vehicle:TVehicle,torque:Float,tire:Int=-1)
vehicle.SetTorque(torque,tire)
EndFunction
Rem
bbdoc:Sets a tire's steering angle
EndRem
Function SetVehicleSteerAngle(vehicle:TVehicle,angle:Float,tire:Int=-1)
vehicle.setsteerangle(angle,tire)
EndFunction
Rem
bbdoc:Sets a tire's braking force
EndRem
Function SetVehicleBrake(vehicle:TVehicle,brake:Float,tire:Int=-1)
vehicle.setbrake(brake,tire)
EndFunction
Rem
bbdoc:Returns the tire's matrix
EndRem
Function GetTireMatrix:TMat4(vehicle:TVehicle,tire:Int)
Return vehicle.gettirematrix(tire)
EndFunction
Rem
bbdoc:Returns 1 if the specified tires are in the air
EndRem
Function VehicleIsAirborne:Int(vehicle:TVehicle,tire:Int=-1)
Return vehicle.IsAirborne(tire)
EndFunction
Function VehicleSpeed:Float(vehicle:TVehicle,tire:Int=-1)
Return vehicle.getspeed(tire)
EndFunction
-
Leadwerks
-
- Posts: 569
- Joined: Fri Oct 27, 2006 2:54 pm
by Julio Jerez » Tue Jun 23, 2009 2:29 am
Leadwerks wrote:Here are some things I think would help make it better:
-Return the speed or omega of a tire, to calculate engine RPMs and engine sound pitch.
-Align the tires to any direction.
-Return the normal of the ground a tire hits.
-Pick filter callback so the tires don't have to collide with everything, or the chassis OnAABBOverlapDo() callback could be used to tell if an object is collidable with the tire.
Your wish is my command,
I thsi k tah of all of those the teh harder is this "Align the tires to any direction"
I just put the SDK that fizxes that,
http://www.newtondynamics.com/downloads/NewtonWin-2.03.rar- Code: Select all
For example to create a car joint with a car moving along the x axis you can do this
1 0 0 0 // car direction of motion in local space
0 1 0 0 // up vector In local space
0 0 1 0 // tire rotation axis in local space
0 0 0 1 // always zero vector
// if your can geometry is oriented alone the z asis , then you set the chassis matrix to this
0 0 1 0 // car direction of motion in local space
0 1 0 0 // up vector In local space
-1 0 0 0 // tire rotation axis in local space
0 0 0 1 // always zero vector
in yor code you can do this
- Code: Select all
Function Create:TVehicle(chassis:TBody,tires:Int=4)
Local vehicle:TVehicle
If Not InitJointLibrary() Return Null
vehicle=New TVehicle
vehicle.parent=chassis
matrix = {
0 0 1 0 // car direction of motion in local space
0 1 0 0 // up vector In local space
-1 0 0 0 // tire rotation axis in local space
0 0 0 1 // always zero vector
}
vehicle.newtonjoint=DGRaycastVehicleCreate(tires, matrix, chassis.newtonbody)
vehicle.connectlinks()
Return vehicle
EndFunction
and you car will have tire tha spins on the x axis, and teh car move along teh z axis. So you do not have to have special car geometry anymore.
when you try this please let me know if you have any problems.
I will add the other funtionality next which should be very simple.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Leadwerks » Tue Jun 23, 2009 4:17 pm
Awesome, thanks!
-
Leadwerks
-
- Posts: 569
- Joined: Fri Oct 27, 2006 2:54 pm
by Leadwerks » Wed Jun 24, 2009 2:09 pm
Okay, it's working properly. If you use a matrix other than an identity matrix, you have to set the steering angle of each tire to 0 when they are added, or they will still face sideways.
Here is a compiled demo:
http://forum.leadwerks.com/viewtopic.php?f=2&t=4054The only problem that remains is the tire slip on the ground. You can see if you go forewards and then backwards, the tires spin very fast on the ground when the vehicle changes direction, as if there is no friction feeding back to them. I have to add enormous amounts of Torque to get the vehicle to move at all, because if I just add an amount that makes the wheel turn slowly, it has no effect on the vehicle's velocity.
-
Leadwerks
-
- Posts: 569
- Joined: Fri Oct 27, 2006 2:54 pm
by Julio Jerez » Wed Jun 24, 2009 3:35 pm
Ther is some scale issue,
you are using a metric system aren't you.
Also is the Lag because you are running at a fix step?
I will see what is going on with the tire speed, Ther have to be a bug somewhere?
I chekc tonight
I have not checked but It seems to me that somehow there is not tire longitudinal tire Friction, and this is why they slide so eassitly.
I beleive this is set in a material but I am do not remember now. I will see tonight, But I am almost positive that that is the problem.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Leadwerks » Wed Jun 24, 2009 3:53 pm
Ther is some scale issue,
you are using a metric system aren't you.
In my engine, one unit=one meter.
Also is the Lag because you are running at a fix step?
I don't understand what you mean by "lag". The engine updates physics at 60 FPS and interpolates body positions and rotations between the last two physics frames. Maybe that is what you meant?
-
Leadwerks
-
- Posts: 569
- Joined: Fri Oct 27, 2006 2:54 pm
by Julio Jerez » Wed Jun 24, 2009 4:42 pm
I do not think it is interpolating, but that's a different problem.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Thu Jun 25, 2009 12:59 am
Oh I am sorry, It was chppy in my compter at work, bu that was because all teh app running in teh background.
It is fine here at home.
Abou the tire spin, I see the problem, I will fix it, and I will give you the interface to stuff like:
GetAngularVelocity, and GetSlipRatio()
which you can use to plus scheech sound and other effects.
There is a bug still and I just found, it was all on my side, but I beleive tah afer the fix the RayCast car will be unstopable.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Leadwerks » Thu Jun 25, 2009 7:09 pm
Cool, I think vehicles add a good mechanism by which someone could actually get a game made. It seems like a relatively easy genre; no animation, no characters to worry about, gameplay is almost always fun.
-
Leadwerks
-
- Posts: 569
- Joined: Fri Oct 27, 2006 2:54 pm
by VeT » Mon Jun 29, 2009 9:28 am
what a...
Leadwerks, i read your code, make my code the same, and nothing works again.. i'm in despair...
- Code: Select all
NewtonBody* car_body = newton_addentity(me, 1300, NEWTON_CONVEXHULL, onforceandtorque);
NewtonBodySetLinearDamping(car_body,0.005);
float tire_offset[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
NewtonJoint* car_joint = DGRaycastVehicleCreate(4, tire_offset, car_body);
DGRaycastVehicleAddTire(car_joint,NULL,vector(5,-5,-1), 0.5, 0.1, 1, 0.1, 0.25, 70, 5, 1);
DGRaycastVehicleAddTire(car_joint,NULL,vector(5,5,-1) , 0.5, 0.1, 1, 0.1, 0.25, 70, 5, 1);
DGRaycastVehicleAddTire(car_joint,NULL,vector(-5,5,-1), 0.5, 0.1, 1, 0.1, 0.25, 70, 5, 1);
DGRaycastVehicleAddTire(car_joint,NULL,vector(-5,-5,-1), 0.5, 0.1, 1, 0.1, 0.25, 70, 5, 1);
while(me!=NULL)
{
DGRaycastVehicleSetCustomTireTorque(car_joint,1,1500);
DGRaycastVehicleSetCustomTireTorque(car_joint,2,1500);
camera_func();
wait(1);
}
maybe i forget to init something, or maybe its the trouble with parameters?
i see no difference between our codes: i create NewtonBody(), then DGRaycastVehicleCreate(), then DGRaycastVehicleAddTire()... what else is needed?
-
VeT
-
- Posts: 84
- Joined: Thu Jul 31, 2008 11:31 am
Return to User Gallery
Who is online
Users browsing this forum: No registered users and 16 guests