x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to dynamically control acceleration of a vehicle

Hey guys, I'm trying to control the acceleration of a vehicle dynamically. The purpose is to have different acceleration rates + max speed such that vehicle will travel in different speed across different roads. (Ex, Highway -> Fast, city road -> a bit slower, mud -> very slow). It seems that friction does not do anything when the vehicle is going forward (which makes sense since the friction should only relate when the vehicle's wheels are skidding, not rolling). Setting MaxRPM dynamically does not work :(. And I can't set the velocity of the vehicle either. (there is only get function).

Please Help! Thanks in advance

Product Version: UE 4.11
Tags:
more ▼

asked May 12 '16 at 06:17 PM in C++ Programming

avatar image

jlim521
3 2 3

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first
 VehicleGame.Build.cs
         
         PrivateDependencyModuleNames.AddRange(
             new string[] {
                 "Slate",
                 "SlateCore",
                 "PhysX",
             }
         );
 
 
 
 
 class UVehicleMovementComponentBoosted4w
 
 VehicleMovementComponentBoosted4w.h
 
     /** Wheel Lat Stiff */
     UFUNCTION(BlueprintCallable, Category = "Wheel")
     void SetWheelLatStiff(int32 WheelIndex, float LatStiffValue, float LatStiffMaxLoad, float LongStiffValue, class UTireType* TireType);
 
     /** Wheel Friction*/
     UFUNCTION(BlueprintCallable, Category = "Wheel")
     void SetWheelFrictionScale(int32 WheelIndex, class UTireType* TireType);
 
     
 VehicleMovementComponentBoosted4w.cpp
     
 #if WITH_PHYSX
 #include "PxVehicleWheels.h"
 #endif //WITH_PHYSX
 
 
 void UVehicleMovementComponentBoosted4w::SetWheelLatStiff(int32 WheelIndex, float LatStiffValue, float LatStiffMaxLoad, float LongStiffValue, class UTireType* TireType)
 {
 
     if (WheelIndex >= 0 && LatStiffValue > 0.01 && LatStiffMaxLoad > 0.01 && LongStiffValue > 0.01 && Wheels.Num() > WheelIndex)
     {
         Wheels[WheelIndex]->LatStiffValue = LatStiffValue;
         Wheels[WheelIndex]->LatStiffMaxLoad = LatStiffMaxLoad;
         Wheels[WheelIndex]->LongStiffValue = LongStiffValue;
         Wheels[WheelIndex]->TireType = TireType;
 
         // init tire data
         // physx::PxVehicleTireData PTireData;
         physx::PxVehicleTireData PTireData;
         PTireData.mType = Wheels[WheelIndex]->TireType ? Wheels[WheelIndex]->TireType->GetTireTypeID() : GEngine->DefaultTireType->GetTireTypeID();
         PTireData.mLatStiffX = Wheels[WheelIndex]->LatStiffMaxLoad;
         PTireData.mLatStiffY = Wheels[WheelIndex]->LatStiffValue;
         PTireData.mLongitudinalStiffnessPerUnitGravity = Wheels[WheelIndex]->LongStiffValue;
         
         PVehicle->mWheelsSimData.setTireData(WheelIndex, PTireData);
     }
 
     
 }
 
 void UVehicleMovementComponentBoosted4w::SetWheelFrictionScale(int32 WheelIndex, class UTireType* TireType)
 {
     if (WheelIndex >= 0 && Wheels.Num() > WheelIndex)
     {
         Wheels[WheelIndex]->TireType = TireType;
         // init tire data
         // physx::PxVehicleTireData PTireData;
         physx::PxVehicleTireData PTireData;
         PTireData.mType = Wheels[WheelIndex]->TireType ? Wheels[WheelIndex]->TireType->GetTireTypeID() : GEngine->DefaultTireType->GetTireTypeID();
         PTireData.mLatStiffX = Wheels[WheelIndex]->LatStiffMaxLoad;
         PTireData.mLatStiffY = Wheels[WheelIndex]->LatStiffValue;
         PTireData.mLongitudinalStiffnessPerUnitGravity = Wheels[WheelIndex]->LongStiffValue;
 
         PVehicle->mWheelsSimData.setTireData(WheelIndex, PTireData);
     }
 }
more ▼

answered Jun 23 '16 at 04:46 PM

avatar image

Gelani
73 3 6 13

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question