Jump to content

HOw to simulate hand brake?


Alessandro
 Share

Recommended Posts

Hello,

I need to simulate hand brake in standard LE vehicle built-in.

I tried to use AddTorque but it is difficult to manage, since reversing tire force (rear wheels) I cannot really stop the vehicle, and somtimes the vehicle start to run in the opposite direction.

 

Is there any other way to do that?

 

local myVel = self.chassis:GetVelocity(0)
myVel = (myVel.x + myVel.y + myVel.z) * 2.5

if KeyDown(KEY_SPACE) == 1 then

	if math.abs(myVel) > 30 then
		self.car:AddTireTorque(-10000, 2)
		self.car:AddTireTorque(-10000, 3)	
	else
		self.car:AddTireTorque(0, 0)
		self.car:AddTireTorque(0, 1)			
		self.car:AddTireTorque(0, 2)
		self.car:AddTireTorque(0, 3)			
	end
         end

Link to comment
Share on other sites

You need to add negative torque only if the speed of car is greater than some treshold. And of course you need to scale the negative torque also, so that you don't add a fixed value, but one which is aiming to the stop speed.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Hi personally i put force on Y axis depending of velocity and adding less friction to body

 

as my code is "almost" working as i wanted, here it is:

 

local roue
           local air = true
           speed=nil
           for roue=0,3 do
               if carobject.vehicle:TireIsAirborne(roue)==0 then
               speed = math.abs(carobject.model:GetVelocity(0).z)
               air = false
               break
               end
           end
           ----si vh sur terre on freine
           if not air then
           chassis:SetFriction(0.3,0.2)
           chassis:SetForce(Vec3(0,-300+speed,0)) 
           end

 

hope it helps

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

Link to comment
Share on other sites

Thank you both of you.

 

@Lumooja that the approach I had, but sometimes I have problems when car is near the treeshold, or even near speed 0. In fact, when I drive a car, I expect that if I use the handbrake the car completely stopped, but using AddTorque (or similar) it is almost impossible to set the precise force to let the vehicle stop and not starting to go in the opposite direction!

 

@diedir I tried a solution similar to yours (using friction, in order to allow the car stop completely), but it seems friction on the chassis has no effect ( I even tried huge values like 10000 but nothing!). Furthermore I cannot apply friction to the tires since the tires are not physics based, but they are controlled by Josh's vehicle algorithm.

 

Do you use tires as models (LoadModel) and not as mesh (LoadMesh)? When I tried to use tires as models I could not apply entityType for collsions since LE locked (going VERY SLOW). And if I simply load LoadModel(tire) it seems it has no real effect.

 

I think I will need definitively spend some time to make a real Newton vehicle, since I'm creating a free-roaming game based on vehicles, and I need good car physics. I'm working with this non-physics vehicle (createed by Josh) but it seems really limited for my purpose.

 

It's funny that LE is presented as a system to make vehicles with arbitrary tires, but no one knows how to do that (and Josh does not help us in any way), and the only vehicle created does use physics in a limited way, just to create a car arcade-style.

 

However, I will try again using Newton physics and joints, and if you have any news from this point of view, please keep me informed ( I will do the same if I will be able to get good results with Newton).

 

Cheers

Link to comment
Share on other sites

Yes, I fully agree with you!

 

Maybe you should mail Josh directly if it's really urgent. Now that he is working on LE3 he said that no new feature would be added to LE 2.4 only bugfixes, so if you want him to add things you'll probably have to argue more (especially if you are an indie and not a game studio with a game near completion.)

It's fully understandable that one person alone will have difficulties to write a new engine while expanding the old one. But sometimes he makes exceptions when he thinks there is no good workaround, like here http://leadwerks.com/werkspace/index.php?/topic/2763-setworldcullrange-new/page__p__25875#entry25875.

so you can try to ask him, but my personal feeling is that this was an exception. I don't know Josh much, it's just my feeling.

Damn, if only Josh could do something for Ywa, now that i found someone really motivated in producing a pascal written game, and probably skilled enought to succed, i would be disapointed if this stopped him.

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

I will try to send him an email.

In fact basic vehicle is nice and lighter than a full newton based one (in terms of cpu resources). SO if he could insert some other functions like "friction", "setTorqueForce", "setWheelMass", "setVehiclePivot" one could really make a more realistic one (and one can create several vehicles with different characteristics for each one).

 

Thank you.

Link to comment
Share on other sites

Damn, if only Josh could do something for Ywa, now that i found someone really motivated in producing a pascal written game, and probably skilled enought to succed, i would be disapointed if this stopped him.

You're so kind. haha :)

 

@ Alessandro: Please let me know if Josh replies to you. Would be nice if you could actually link him to this topic/thread.

Link to comment
Share on other sites

You need to use the negative force of the current speed of the vehicle, and not an absolute number. Then it won't go into the opposite direction after it has stopped.

TVec3 zvel=GetBodyVelocity(chassis).Z;
AddTireTorque(car,-zvel,0);
AddTireTorque(car,-zvel,1);
AddTireTorque(car,-zvel,2);
AddTireTorque(car,-zvel,3);

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

You need to use the negative force of the current speed of the vehicle, and not an absolute number. Then it won't go into the opposite direction after it has stopped.

TVec3 zvel=GetBodyVelocity(chassis).Z;
AddTireTorque(car,-zvel,0);
AddTireTorque(car,-zvel,1);
AddTireTorque(car,-zvel,2);
AddTireTorque(car,-zvel,3);

 

No, I tried it, but applying negative forces they decrease car speed, then it will start to go in inverse. It is logical: if apply a negative force to the tires, they rotate in the opposite direction.

You can try it by yourself.

 

I used a different approach (not perfect, but it works).

1) I apply opposite force until the speed is very low(I calculate vehicle speed by adding all velocity components x,y,z).

2) when the speed is very low, then I apply a big DUMPING force (like a friction) and the car start stopping really.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...