Delete a BodyVelocity while still keeping the velocity

Title explains it all. How can I delete a bodyvelocity without it canceling out all the velocity.

4 Likes

Have you tried slowly reducing the velocity and then deleting when it reaches zero?

You need to set the Part’s AssemblyLinearVelocity equal to the BodyVelocity’s Velocity property before you destroy the BodyVelocity.

Do you need to see it in code, or does that make sense?

Makes sense and tbh i was thinking that. Just wondering if there was an easier way

1 Like

I just built a quick test with a single part, and the part kept its velocity even after I deleted the BodyVelocity. Is your part’s velocity changing after deleting the bodyvelocity?

Well, I have a big rocket. Upon stage seperation, the bodyvelocity gets removed. Like real life. Now when the bodyvelocity gets deleted it deletes all the velocity from the bodyvelocity also. And I just tried do part.assemblylinearvelocity = part.bodyvelocity.velocity. Didnt work

1 Like

You might want to set the velocity after deleting the BodyVelocity, not before. You also might want to delay a single physics frame before setting the velocity to ensure that the BodyVelocity’s grip on the part is gone.

local velocityStore = part.BodyVelocity.Velocity
part.BodyVelocity:Destroy()
wait()
part.AssemblyLinearVelocity = velocityStore

Also, real life rockets would use BodyForce, not BodyVelocity. That would make your life easier if you did it that way, as you could just set the BodyForce to zero, and it would work exactly like real life.

but i dont think you can get bodyforce to increase like acceleration.

1 Like

I’m not sure I understand. BodyForce.Force takes a Vector3 that can be changed as often as you’d like to any value, so you can change the acceleration however you’d like.

In a real rocket, that still isn’t what is happening, as the force is constant, but the mass is decreasing. That is why acceleration increases. If you reduce the mass of a rocket part over time in a script, a constant BodyForce will produce ever-increasing acceleration.

It’s not like it’s rocket-sci…errm nevermind.

2 Likes

No no i understand what your saying. the fuel burnt reduces the mast allowing for more thrust or something like that. It’s just if you dive into the depths of that complex rocket science, simulating it in game is either really hard or impossible. Bodyvelocity is the easiest and most realistic option imo. Btw. It sais that runservice is not a valid member of datamodel.

1 Like

It’s not impossible. It’s actually very little change on your end to get a realistic result. BodyVelocity is nowhere close to actual rocket behavior.

All you need to do is set a constant BodyForce and then set that BodyForce to zero upon separation. Then you need a script in the part that reduces its mass over time.

I’m going to code it out real quick for you. What material is your part made of?

My main part? Because i think they are all either smoothplastic or plastic. Also, I’m using an accelerating script that is also my lookvectore / horizontal velocity script. Do I just need to change out the bodyvelocity bit of the script for bodyforce?

Yes, you just need to swap out BodyVelocity with BodyForce.

alrighty. thanks a lot - 30 word thingy

Ok I just tested it and it seems to work as expected.

local part = script.Parent
local rocketForce = 5000  --tweak this number to get the rocket thrust you want. 5000 is probably nowhere near correct
part.BodyForce.Force = part.CFrame.LookVector * rocketForce
local numSecondsOfBurnTime = 10
local density = 0.7
local friction = 0.3 --standard value for plastic
local elasticity = 0.5 --standard value for plastic
local waitInterval = 0.1  --loop interval in seconds
local totalLoopIterations = numSecondsOfBurnTime/waitInterval
local densityWhenFuelEmpty = 0.01 --set to whatever. 0.01 is the lowest possible value
local amountOfDensityToRemoveEachIteration = (density-densityWhenFuelEmpty)/ totalLoopIterations  --0.01 is the lowest density

for i = 1, totalLoopIterations do
	wait(waitInterval)
	part.BodyForce.Force = part.CFrame.LookVector * rocketForce
	density = density - amountOfDensityToRemoveEachIteration
	part.CustomPhysicalProperties = PhysicalProperties.new(density, friction, elasticity)
end	
part.BodyForce.Force = Vector3.new(0,0,0)  --rocket fuel is empty. set force to zero

Ok so it looks… amazing, but it starts to get a bit complex now. So, do I put this in my acceleration script? Or in my main handler. Btw I can’t believe you casually just wrote this.

This script is basically the acceleration script. It assumes its parented to the part that has a bodyforce as a child. Don’t be inntimidated by the script. The only things you need to change are the lines:

local numSecondsOfBurnTime = 10
local rocketForce = 5000

Just need to figure out through testing how much force and for how long the engine needs to burn.

Okay, and for the next stages, can I do an instance.new? As I found through testing that having multiple bodymovers sometimes just breaks it.

It’s hard to give precise advice, because there are many ways to do it. My response depends on how your rocket parts are set up and how you are implementing the separation bits. Can you send a screenshot of your game explorer with the rocket parts and children expanded out? Can you also explain how you intend to do the separations?

Alright, so to put it simply. My 1st stage / lower stage is welded to my second stage. second stage welded to third. third welded to csm on my saturn v. csm welded to my crewcapsule. launch escape welded to my crew capsule. now i already have a gravity script so I basically just delete the weld as every stage has a main part that everything on that stage is welded to. Hope it makes sense?