Struggling to dampen single/multipe vector3 values

Ive been stuck on this for a while ,any help is appreciated alot

im trying to make a drone; its moved by vectorforces

if MovementTable[keyPressed.Name] and not applyingForces[keyPressed.Name] then
			
			local archive = keyPressed
			--table.insert(applyingForces, keyPressed.Name)
			applyingForces[keyPressed.Name] = MovementTable[keyPressed.Name]
			
			vectorForce.Force += MovementTable[keyPressed.Name] * DronePM:GetMass() * 6
			--DronePM.AssemblyLinearVelocity += MovementTable[keyPressed.Name] * DronePM:GetMass() * .2
			
			while task.wait(.1) do
				if not uis:IsKeyDown(archive) then
					
					vectorForce.Force -= MovementTable[archive.Name] * DronePM:GetMass() * 6

im trying to dampen the speed of the direction the vectorforce was moving it in

it works how i want when i only move in a single positive direction(only right or up or forward)

but when i move in a -vector direction, it starts to bounce and stop abruptly unlike the positive direction

and when i try to stop while holding down two directions, it completely stops the drone in all directions

this is what i have in total for the movement and dampening function

while task.wait(.1) do
				if not uis:IsKeyDown(archive) then
					
					vectorForce.Force -= MovementTable[archive.Name] * DronePM:GetMass() * 6
					applyingForces[archive.Name] = nil
					
					local damperAmount = .1
					local x1,y1,z1 = 0,0,0
					local archiveVector3 = MovementTable[archive.Name]
					--print(archiveVector3)
					
					local secondaryAxis
					for _, v in MovementTable do
						if applyingForces[archive.Name] and  v == -applyingForces[archive.Name] then
							
							secondaryAxis = v
							
						end
						
					end
					
					local taskvariable
					
					while task.wait(.1) do
						
						if applyingForces[archive.Name] then
							print("break1") break
						end
						
						local wished = DronePM.AssemblyLinearVelocity * archiveVector3
						
						print(wished, wished.Magnitude)
						
						
						DronePM.AssemblyLinearVelocity = wished * damperAmount
						
						if wished.Magnitude <= .2 then
							print("killed by speed") break
						end
						
							
							
					end
                break
end

this is the movementTable thats being referenced in the function

local MovementTable = {
	
	["W"] = Vector3.new(0,0,-6),
	["D"] = Vector3.new(6,0,0),
	["A"] = Vector3.new(-6,0,0),
	["S"] = Vector3.new(0,0,6),
	["E"] = Vector3.new(0,6,0),
	["Q"] = Vector3.new(0,-6,0)
	
}

i want to basically only slow down the direction that no longer has force on, for example; if i let go of the D key, i’d want the velocity to dampen the -x value only (since it was moving left) and leave the rest of the vector3 the same

same thing for if i had the W and D let go but still holding the S key, i’d only wanted the +Z and -X value damped and the S key (+X value) left the same

let me know if i need to describe or add more
thanks

Ive been stuck on this for two days :frowning:

Okay, instead of a dampening factor, you could try a resistive force. Basically apply a force in the direction opposite to movement that is proportional to it’s speed. This is basically air resistance.

You can also raise the velocity to a power to make its effects more harsh.

Psuedocode:

F_Resistant = -1 * drone.Velocity * dampeningFactor
– another way(more like air resistance in real life)
F_Resistant = -1 * drone.Velocity * drone.Velocity * dampeningFactor

1 Like

Hi thanks for responding
what would f_resistant be? Is that another vectorForce on the dronepart? - sorry im new to forces

It’s simply a force that is applied to the object. It is a vector. So put a vector force in the drone, and set it’s force every frame to formula I showed you.

To move the drone, add a force to the drone.

1 Like

edit: i had to change resistance relative force to world
thank you alot

1 Like

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