As far as masking goes, I think you don’t need to set a mask - just use an image which looks like churned up mud, but with some transparency to make it look right when it is added on top of the rest of the ground.
Here’s my understanding of the following lines (maths is not my forte, either)…
Calculate the amount of force to apply to the powered wheels needed to drive the vehicle. This is based on the current direction of the wheel with the motor and the speed the vehicle is currently moving. The actual maths is a form of rotation maths (the 180/pi gives it away.) In short, this works out which direction the force is applied to the drive wheels.
[lua] wheelRDirectionX = math.sin(motor1.rotation/180*math.pi) * TRACTOR_SPEED
wheelRDirectionY = math.cos(motor1.rotation/180*math.pi) * TRACTOR_SPEED
[/lua]
This takes the force (calculated above) and applies it to the wheels to drive the tractor. This is basically the simulation of the engine providing power to the wheels. In fact, what it is really doing is pushing the wheel objects in the direction they should be moving. Because the wheels are attached to the rest of the tractor they will cause the tractor to look like it’s driving in that direction.
[lua] motor0:applyForce(wheelLDirectionX,-wheelLDirectionY,motor0.x,motor0.y)
motor1:applyForce(wheelRDirectionX,-wheelRDirectionY,motor1.x,motor1.y)
[/lua]
This applies rotational (angular) force to the pivoted object connected at the joint. In effect, this simply turns the wheels by applying force to the pivot joint.
[lua] --Steering
local mspeed
mspeed = math.rad( steeringAngle - motor0Joint.jointAngle )
motor0Joint.motorSpeed = mspeed * STEER_SPEED
mspeed = math.rad( steeringAngle - motor1Joint.jointAngle )
motor1Joint.motorSpeed = mspeed * STEER_SPEED[/lua]
So, all in all, we have 3 bits of code: The first works out how much force should be applied in the direction the tractor is driving. The second applies the force to the wheels, causing the tractor to move. The third turns the wheels, if they are being steered. [import]uid: 8271 topic_id: 34974 reply_id: 139649[/import]
