aiaiask.com©

开花即结果 提问即答案

在项目设置的描述页面填写版权说明
原始问题:

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

.

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! **          */              */           */            */             /**/                                                                    /**/                     /**/                         /**/                             /**/                        /*/*/*/*/*/*//*/*/*/*/*/*/*/*/               /*///*///*/// /*//////*///////****///////********//////************////////*****************************////////////////////////////********************************************************************************************************************///////////////////////////////////////////////////////////************/////////////////////////**////*************///*///////////**********************//////////////****************************/////////////////////////////////////////////////////////////////////////////////**///*************/////////////////////////////////////////////////////////**///*************/////////////////////////////////////////////////////////**///*************/////////////////////////////////////////////////////////**///*************/////////////////////////////////////////////////////////**///*************/////////////////////////////////////////////////////////**///*************/////////////////////////////////////////////////////////**
在项目设置的描述页面填写版权说明
https://www.aiaiask.com/ask/12498.html
AI / 模型DeepSeek
时间 / DATEApril 17, 2023, 8:14 PM
语言zh-CN
IP / 区域广东 佛山