How to calculate Vector Force motion?

How do I calculate the Vector Force going on this path?
image
Like up and down and stuff…
I have tried a lot of numbers but nothing works.
Also the formula I am using on the graph is sin(x)

Do you want a part to follow the wave you described? Do you want it up and down, left and right, etc. and do you have any examples. Also, do you want it’s rotation to change or stay constant?

Yea, I want it to follow the wave I described.
I don’t have examples currently, but I remember it being in a combat game or smth…
It can stay constant.

this is probably what you want?

local part = Instance.new("Part", workspace)
local rs = game:GetService("RunService")
local start = tick()
rs.Heartbeat:Connect(function()
	local span = tick() - start
	local modified = math.sin(span)
	part.Position = Vector3.new(part.Position.X, part.Position.Y, modified)
end)

sorry if i’m wrong, i’m very bad at math

I don’t know how I would implement that in my script portion:

  local function createPunchForce() 
		local vel__ = Instance.new("VectorForce", hrp)
		vel__.Name = 'PunchForce'
		vel__.Force = Vector3.new(0, 2500, math.sin((math.pi*2)/2) * 2000)
		local torso: Part = c:WaitForChild("Torso")
		local back_attach: Attachment = torso:WaitForChild("BodyBackAttachment")
		vel__.Attachment0 = back_attach
		hum:TakeDamage(15.5)
		task.wait(3)
		vel__:Destroy()
	end

what are you using sin() for, and what are you trying to move?

I’m saying, how would I implement that into my script?
It’s just a prev solution I tried
It’s a character model.

yes i’m asking that to understand how i would implement it.

  local function createPunchForce() 
		local vel__ = Instance.new("VectorForce", hrp)
		vel__.Name = 'PunchForce'
		vel__.Force = hrp.CFrame.LookVector * 2000
		local torso: Part = c:WaitForChild("Torso")
		local back_attach: Attachment = torso:WaitForChild("BodyBackAttachment")
		vel__.Attachment0 = back_attach
		hum:TakeDamage(15.5)
		task.wait(3)
		vel__:Destroy()
	end

though this doesn’t use sin(), this might be what you are looking for. (also, (math.pi*2)/2) * 2000 is (math.pi * 2000) simplified

Works, but moving the model takes too long.

  local function createPunchForce() 
		local vel__ = Instance.new("VectorForce", hrp)
		vel__.Name = 'PunchForce'
		vel__.Force = hrp.CFrame.LookVector * 10000000 -- change the speed.
		local torso: Part = c:WaitForChild("Torso")
		local back_attach: Attachment = torso:WaitForChild("BodyBackAttachment")
		vel__.Attachment0 = back_attach
		hum:TakeDamage(15.5)
		task.wait(3)
		vel__:Destroy()
	end

Ok, I want the character to go up too… just like the image I showed.

  local function createPunchForce() 
		hrp.CFrame += Vector3.new(0, 10, 0) -- change the y axis to increase height.
		local vel__ = Instance.new("VectorForce", hrp)
		vel__.Name = 'PunchForce'
		vel__.Force = hrp.CFrame.LookVector * 10000000 -- change the speed.
		local torso: Part = c:WaitForChild("Torso")
		local back_attach: Attachment = torso:WaitForChild("BodyBackAttachment")
		vel__.Attachment0 = back_attach
		hum:TakeDamage(15.5)
		task.wait(3)
		vel__:Destroy()
	end

(this is constant height)

if you want the character to move in a sin like motion, try this. it updates the force through a while loop.

  local function createPunchForce() 
		local vel__ = Instance.new("VectorForce", hrp)
		vel__.Name = 'PunchForce'
		local torso: Part = c:WaitForChild("Torso")
		local back_attach: Attachment = torso:WaitForChild("BodyBackAttachment")
		vel__.Attachment0 = back_attach
		hum:TakeDamage(15.5)
         
		task.spawn(function() 
			task.wait(3)
			vel__:Destroy() 
			vel__ = nil
		 end

		 while vel__ do
		 	vel.Force = Vector3.new(0, 2500, math.sin(tick()) * 2000)
		 end
	end

It lags the game a lot, tried adding a task.wait(), still laggy…
Ty for the help tho

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