This is starting to make me want to learn Unreals c++ API, the lack of real- debugging is what holds me back. Anyways.
My studio is creating a submarine simulator game with the community ocean plugin as the base.
We want to have as many as 10 classes of ships the player can control, and of course there will be dozens of enemy ships that can change speed, accelerate away from torpedoes in range etc. We have a working controller for one class of submarine but its tweaked with someting like 40+ variables to get it just right. So I thought. Why not make a custom component that works as an “engine” that can be re-used over and over again; modularity.
So I start with just getting a basic “ahead flank” (war power, 110% engine power basically). Using the add actor local offset with an x of say +50 got me the right speed, but it instantly speeds up to that rate.
So I tried using some of my Unity knowledge to use just vector3’sor 3Vectors whatever Unreal calls them to make it accelerate at a certain rate to top speed and then continue at that speed. I got as far as the picture below before giving up after a few days of experimenting. I’m using the scene component base class as you can see from the top.
What might be the best way to get any ship this is attached to to accellerate at a rate defined by a variable flank_speed_accell at x cm/s up to max_speed_flank or on the opposite end back_slow_accel at -x cm/s up to max_backslow_speed. Using the vector method you see I was able to get it to accelerate, get up to speed, but then it would slow down at the same rate and stop as it reached its VInterpTo target. I traced this problem down to the fact that the target was for whatever raeson basically the world origin (something like (1.5,0.5,0.5 reletiev to the world) so it would basically deaccellerate just before getting to that point and then stop dead in its tracks there. When I changed the target for VInterpto to get actor location + vector (50,0,0) with an interp rate of I think 1 or 2 set manually it did the exact same thing as when I just used a single AddActorLocalOffset(delta=50,0,0) node so it instantly starts moving at 50cm/s.
How can I accelerate using that node smoothly, or is there a better way to do it, or was I having the right idea using vectors and AddActorLocation?
TLDR: Im trying to make a reusable ‘engineMovement’ component that is used for propelling a ship in its positive and negative x direction. (Forwards and backwards) and be able to use it on any class of ship. Should I be using an empty actor class? It seems im limited in what BP nodes I can use with the scene component class. The main reason behind doing this is so that we dont ahve to write a custom controller for each calss of submarine/boat because a) its extremely messy (huge event graph, nested macros, tons of functions, tons of variables that im sure take up huge amounts of memory allocation), just looking towards saving in the future.
I’ll add as usual that I came to UE4 from Unity Nov. 2014 but after realizing I didnt have the or skills to code using unreals API (My C++ is rusty and not having live debugging makes development very very slow), so I’m kindve missing the modularity of writing a script, then adding it to a gameobject (actor) and tweaking its public variables on a per gameobject (actor) basis in the editor.
The modularity is what im missing, but forgiving that, I’m having a hard making a ship slow down and speed up nice and smoothly. I can account for drag and stuff later. Its tough because I cant just hold the throttle down I need to be able to have an input event cause the ‘engine’ to go x speed (certain RPM really, but it gets the boat to x speed over y seconds)
Heres one of the images I took while I was messing around. I’m having a hard finding any info for non-wheeled or ship baaed vehilcles. Everything is either wheeled, non gravity (space), throttle controlled or a mix of 2 or 3 of the former.
Thanks. I’ve really been learning alot about UE’s BP API. The community here is great. The documentation is whats lacking. I intend to start writing documentation down with blueprint examples on my website or a nice e-book for un-common tasks like this. I cant just slap a playermovement component on our pawn based submarine and pawn based AI enemy ships.
Edit: This function is getting called every tick as soon as I activate it in the component owners BP using an action mapping event (a key press event) also everything except current_speed has default values that dont change anywhere else, infact they are all local values except .deltaTime that is the very first variable set from EventTick(deltatime). Should that maybe be calculated every frame in the owners BP and then cast and get or is it fine the way I have it set to calculate forward velocity?