How do I set the velocity of a mesh for each axis individually (but at the same time) in blueprints?

Hello!

What I’m trying to do is simulate a spaceship’s acceleration/deceleration. The closest I got to this is by adding/subtracting an amount every tick. However, at low speeds this causes some weird movement and I also need to additionally set the ship’s speed to dead zero whenever it slows to a speed at which it wouldn’t be noticed by the player. If I do not do this, then the ship would just keep jumping over or under the zero (or whatever the player sets it to) target speed on every axis, causing it to constantly apply thrust and switch it from +X to -X and vise versa, for instance.

To that end, I think FInterpTo Constant is much better, but then I have my current problem. I cannot come up with a way to set only the ship’s X axis speed without touching the other 2 axes and vise versa. And it’s not like linking the ships’s current Y and Z speeds helps either - ‘cause then it overwrites the values from the other two axes if not in inertial mode, not to mention that since (for whatever reason) the engine adds Y and Z speeds when pressing +X only, the script tries to kill that fractional speed as well, which immediately attempts to zero-out the X speed as well, forcing the ship to basically stay in place, because the scripts for each axis are actively fighting to kill each others’ speeds. I tried using a structure with 3 floats (since it allows for setting just one member, rather than all three), but then I realized it would do no good unless I can come up with some insanely clever select float script as well.

I hope I described my issue in a way you can understand it. In other words… I would like to simulate a spaceship’s Newtonian physics acceleration/deceleration without having the main and aux thrusters fighting each other.

hi Exp :slight_smile: I think your issue is quite solvable… but are you using a Pawn, or Character… with physics enabled (AddForce, AddInput, AddTorque etc) or Pawn/Char movement inputs? As a general rule, it’s ok if your ‘engines’ are pushing in different directions… every tick, UE4 will just use the balance of Forces to calculate the final result.

Btw… when you are further along, if you are using Physics, please consider the effect of Tick and the different clock speeds of different machines. I’d look for BoredEngineer’s (he’s a flipping wizard) FREE MMT plugin to fix this (involves substepping etc.). This is quite a deep topic, but the MMT plugin solves a whole bunch of challenges.

I’m actually using a Pawn, but moving the skeletal mesh directly (i.e., there is no movement component). Only reason I’m using a pawn is so the player is spawned as a pilotable ship (can’t seem to be able to use any other type of Blueprint for the default pawn in the Game Mode one).

So the skeletal mesh has physics enabled and you are using AddForce?

With a couple of differentengine locationsou might consider Physics Thruster components, also look at Linear Damping settings on your physics root itself (this will help with slowing down the pawn… 1 or 2 is a good starting point… the default is .001 which means almost no friction, space would I think have zero friction theoretically).

With a non-spherical or non symmetrical physics object, you might run into issues as to where the center of mass is calculated by UE4 (solvable, but worth knowing)

Abyway, keep coming back here with the details of what you are trying (ideally with screeenshots) and we’ll try to help you out

Not AddForce, rather taking the velocity at the time of a tick, then calculating what the velocity would be after applying thrust. Then, feeding that into a Make Vector with two of the axes having no input, then using Unrotate Vector to make sure the velocity change is relative to the direction that the mesh (player) is facing, finally feeding that into a Set All Physics Linear Velocity node.

Sorry, no can do on the screenshots, 'cause I’m at work and firing up UE4 would show up on the time tracking software :smiley:

No particular reason, other than having made a movement axis input for each axis (X (F/B), Y (L/R), Z (U/D)). I’ve already made the manual speed increase/decrease and it works flawlessly; it’s the automatic velocity increase/decrease in speed that the ship does if not in Inertial mode and in the absence of player input for any axis - which is the flight computer trying to reach the target speed on each axis that the player inputs (meaning it can be something other than dead zero).

However, I don’t use AddForce at location or thrusters because that would require positioning them correctly by the nanometer, otherwise they don’t propel the ship in the correct direction.
I’ve tried this for a very long time and couldn’t do it, so I just gave up.

I understand… is there a reason that you seem to be trying to SetLinearVelocity several times (one for each axis) on Tick? It sounds like you’ve considered creating a vector from the individual force floats, then plugging in the vector once on tick… this would work.

One thing, as Clockwork commented on one of my posts recently, SetLinearVelocity can give some unusual results… and any variations in Tick speed will likely affect your spaceships speed.

I understand what you are saying about AddForceAtLocation and Physics Thrusters, but AddForce would act on the center of mass (or pivot… I honestly forget) which might be useful.

Now that I understand what you are looking for a bit better, it sounds like what you need is a PID controller. BoredEngineer (may heaven bless him) has a free controller for download as part of his MMT plugin kit.

At this stage, you may not need all the MMT plugin’s physics tick substepping wizardry to keep your physics stable across varying Tick rates… but further down the line this plugin would also solve these issues btw. For now, you might consider just dropping a one generic little MMT PID controller component onto your pawn for each error (the key variable… could be any measurement) that you are controlling. It works superbly, and is simple to use… it’s more or less a generic spring calculation. No, I’m not selling 'em :slight_smile:
299463-
299465-pawn.jpg

Hey, thanks for the answer, I’ll be sure to look into it. In the meantime, I tried to setup the script differently, but now the ship acts really weird. Links:
Entire BP Input Script
Short recording showing the ship’s exact behavior