How to Create physics based movement?

Im trying to make physics based movement so I can go up ramps and have a bit more freedom while moving. What do I have to change in Tank.cpp Move function in order to move?

You would need to go about adding force to the capsule component. See AddForce and friends as well as AddTorque

I’ll give it a closer look, I’ve moved BasePawn’s CapsuleComp into protected so I can reference it on Tank.cpp. I’ve used AddForce instead of the old movement in the Move function

if (CapsuleComp)
{
FVector Force = FVector::ForwardVector * Value * Speed;
CapsuleComp->AddForce(Force);
}

Unfortunately this doesn’t move my tank at all. I’m a bit lost. Simulate physics is enabled, I’ve tried dropping my tank from a spawn point in the air, gravity works, I just can’t get it to move forward.

Add if you change AddForce to:

// BoneName,
// bAccelChange If true, Force is taken as a change in acceleration instead of a physical force (i.e. mass will have no effect).
CapsuleComp->AddForce(Force, NAME_None, true);

You also need to get the forward vector of the capsule. FVector::ForwardVector is just a constant or (1, 0, 0) i.e. 1 in the X axis.

Hahah, I did it, and now my tank rolls like a ball, and the forward vector of the tank goes everywhere.

is there anyway to get the capsule and basemesh not to roll like a ball?
image

I think I’m going to play around with basic pawns in a new project to get a better understanding of how to move things with physics.

Well the collision is essentially a sphere, a rotated capsule shaped capsule component would probably be better suited, but that can’t be the root component (everything is relative to that so you can’t transform the root component) So you may want to create a wheel/track component.

Oh wow, yeah a wheel system sounds cool, now we’re talking. I see why the course instructor did literal translation. Way easier to follow .

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms