Me and my team are currently trying to speed up my player the longer I hold down the thrust button. With what we have now, the player moves but stays at a constant speed and doesn’t speed up. I’m at a stand still right now because everything we try anymore doesn’t work. Any options?
I haven’t look at your bp but if i had to do that, i think i would use a while loop like idea : with normal speed and max speed : 2 float variables : Input Thrust pressed : delay 0.1 (or on tick ): while speed < max speed : speed = speed + 1. Input Thrust released while speed > normal speed : speed = speed -1. Is that the type of idea you are looking for ?
Edit : i forgot loop to delay and bool to stop loop set in both pressed and released and used in pressed as condition.
This did not fix the problem. What I’ve found out is that “Set Velocity in Local Space” is supposed to rotate the vector with the actor. However, it does nothing. In theory, this should work. However, when I rotate in any direction, it stops moving all together. If I “Set Velocity” based on the Z Axis only, it only moves up, regardless of which direction I’m facing. If I connect the X and Y values in the Blueprint below, and I rotate the “ship” at all, it moves in circles. The print submitted by Mhousse made no change to our problem, though it was appreciated. I don’t know if there is a difference, but we are using 4.6 for this project.
whats connected to the ‘Enter’ input of that gate?..
I’ve done exactly this for a game with ships recently. In my case the ship could only move forward, and when turning all forward moment is instantly turned. So its easier than space ships, but still this should help. It doesn’t use any movement component so if you rely on those for other parts, this can be ignored.
What I did was make BP variables Speed, Acceleration (constant) and MaxSpeed (constant). I used Axis Events, which trigger every frame as long as a key is pressed. W for accelerate (AxisValue = 1) and S for decelerate (-1).
On Axis Events, I did effectively this in blueprint: Speed = Max(Min(MaxSpeed, Speed + AxisValue * Acceleration * WorldDeltaTime), 0). What happens here? I update the speed according to acceleration per second and then make sure its between 0 and max. You could also use -max and max. You can get the WorldDeltaTime as global value and it is correct because axis events trigger every frame when pressed.
On Event Tick, we apply the speed by calling AddActorLocalOffset with as input vector (ElapsedTime * Speed, 0, 0). Check the Sweep on AddActorLocalOffset to check for collision. Because we add local offset we don’t have to worry about rotation. Hope that helps for reference. I would post a screenshot of my BP if I was at my work pc. Good luck!
Michael and crew,
Pardon me for saying so but I think you need to make a decision about how your object will move… A. do you want the physics engine to handle things or B. do you want to tell the ship where to go and when. Doing both is not going to work well.
Looking at your first blueprint I see you are using a projectile movement… this is intended to be a one shot, physics guided object. I tried using it as well because it has all the properties I want to see… but trying to control its movement is to fight against the physics engine.
The controls I use in the example below accelerate me smoothly up to the maximum defined in my project settings… 8000 i think… and decelerate me back to 0 without telling it how fast to go… it knows how fast to go already, “thank you very much!”… I tried and tried to do what you are trying to do and finally realized… dont fight it… just go with the physics…
OH yeah! almost forgot… the input axis value is a float… 0 to 1 (for simplicity sake) in increments too small to count… if it is tied to a button which is just 0 or 1 (pressed or not) then when the button is pressed it will be 1 when the button is not pressed it will be 0. the longer you hold the button down the more 20 strength impulses fire until max speed is reached.
Moose, Thanks for the advice. I didn’t realize what was going on, but I now understand so I appreciate the intel. What is the default setting for the “thrustoffset” variable, or where do you set it? I don’t see where it is set in the Blueprints above.
whenever you make a new variable you have to do a compile to get the values to show.
the setting is always at the bottom of the details of the variable.
I got it to work! Thanks everyone for your help, but I woun