qcode
  • 创作工场专业版,一问多答!更智能、更完整、更原创
  • 这是一个超强内容创作平台,它会写文章、做设计、绘图、敲代码,有问必答!
🔥点击使用-免登录深度版🔥

在项目设置的描述页面填写版权说明

时间2023-04-17 20:14:03 提问来自 广东省佛山市 的网友 分类创作 浏览449
. #include "BattleTank.h" #include "TankTrack.h" UTankTrack::UTankTrack() { PrimaryComponentTick.bCanEverTick = false; } void UTankTrack::BeginPlay() { OnComponentHit.AddDynamic(this, &UTankTrack::OnHit); } void UTankTrack::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) { DriveTracks(); // TODO CLAMP THROTTLE VALUE SO PLAYER CAN'T OVERDRIVE THE TRACKS !!! ApplySidewaysForce(); // TODO CLAMP SIDEWAYS FORCE VALUE SO PLAYER CAN'T OVERDRIVE THE TRACKS !!! CurrentThrottle = 0; // reset throttle after hit so tank doesn't keep going in the same direction } void UTankTrack::ApplySidewaysForce() { // TODO CLAMP SIDEWAYS FORCE VALUE SO PLAYER CAN'T OVERDRIVE THE TRACKS !!! *******SEE ABOVE******* auto SlippageSpeed = FVector::DotProduct(GetRightVector(), GetComponentVelocity()); // get the right vector of tank and then dot product it with velocity to get slip speed (how fast it is slipping) auto DeltaTime = GetWorld()->GetDeltaSeconds(); // how much time has passed since last frame - use this to calculate acceleration (delta velocity / delta time) auto CorrectionAcceleration = -SlippageSpeed / DeltaTime * GetRightVector(); // calculate sideways force to apply to get back on track (acceleration is equal to delta velocity / delta time) ******NOTE: using negative value because we want it going opposite direction of current slip speed***** ***NOTE: GetRightVector gets the right vector of tank which will be the opposite direction of current slip speed so multiply by negative 1*** *** NOTE: divide by DeltaTime because we want acceleration which is change in velocity over change in time*** ******NOTE: multiplying by getrightvector will give us a vector that points in opposite direction of current slippage and has magnitude equal to acceleration****** ***** NOTE: this will give us an acceleration value that will counteract our current slippage and bring us back on track***** ****** THIS IS CALLED ANTI-SLIPPAGE SYSTEM AND IS COMMONLY USED IN CAR PHYSICS GAMES/SIMULATIONS TO KEEP CAR ON TRACK********* *** NOTE: if car isn't slipping then correctionAcceleration will be zero because SlippageSpeed would also be zero****** *** NOTE: If car is slipping left then correctionAcceleration would point right with magnitude equal to how fast its slipping left*** *** NOTE: if car was slipping too fast then correctionAcceleration would be large magnitude pointing right which would counteract the cars slippage and bring it back on track*** **NOTE: We are not actually applying this force directly here but rather passing it off as a parameter into TankMovement component where we can apply it with AddForceAtLocation function! ** **SEE TankMovement Component for explanation on why we do this! ** */ */ */ */ /**/ /**/ /**/ /**/ /**/ /*/*/*/*/*/*//*/*/*/*/*/*/*/*/ /*///*///*/// /*//////*///////****///////********//////************////////*****************************////////////////////////////********************************************************************************************************************///////////////////////////////////////////////////////////************/////////////////////////**////*************///*///////////**********************//////////////****************************/////////////////////////////////////////////////////////////////////////////////**///*************/////////////////////////////////////////////////////////**///*************/////////////////////////////////////////////////////////**///*************/////////////////////////////////////////////////////////**///*************/////////////////////////////////////////////////////////**///*************/////////////////////////////////////////////////////////**///*************/////////////////////////////////////////////////////////**

不满意?免费深度重写!

免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。

上一篇 酶标仪的工作原理 下一篇 谈谈你对新质生产力的认识和理解,题目自拟,字数不少于1000字