Waves are moving too fast compared to character walkspeed

Hello,
I made a wave system, but when I try to move around, the waves are offset too fast compared to my position. I tried dividing the players position but I want it to be as accurate as possible, so I can’t just divide it by some random number.

Video:

Code:

if not game.Players.LocalPlayer.Character then
	game.Players.LocalPlayer.CharacterAdded:Wait()
end

local AssetService = game:GetService("AssetService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local Object = script.Parent
local EditableMesh = Instance.new("EditableMesh")
EditableMesh.Parent = Object

local Player = game.Players.LocalPlayer

local Character = Player.Character
local CharacterPos = Character.HumanoidRootPart
Player.CharacterAdded:Connect(function(New)
	Character = New
	CharacterPos = Character.HumanoidRootPart
end)

local tweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

local Width = 100
local Height = 100

local Offset = 10
local WaveSize = .025
local WaveHeight = 10

local Vertices = {}

for y = 1, Height do
	local raw = {}
	for x = 1, Width do
		local vertexPosition = Vector3.new(x - 1, 0, y - 1) * Offset
		local vertexId = EditableMesh:AddVertex(vertexPosition)
		
		raw[x] = {vertexId, vertexPosition}
	end
	Vertices[y] = raw
end

for y = 1, Height-1 do
	for x = 1, Width-1 do
		local vertex1 = Vertices[y][x][1] :: number
		local vertex2 = Vertices[y+1][x][1] :: number
		local vertex3 = Vertices[y][x+1][1] :: number
		local vertex4 = Vertices[y+1][x+1][1] :: number
		
		local triangle1 = EditableMesh:AddTriangle(vertex1, vertex2, vertex3)
		local triangle2  = EditableMesh:AddTriangle(vertex2, vertex4, vertex3)
	end
end

while true do
	local currentTime = os.clock() / 10
	for y = 1, Height do
		for x = 1, Width do
			local vertexId = Vertices[y][x][1] :: number
			local vertexPosition = Vertices[y][x][2] :: Vector3
			
			local newPosition = vertexPosition + Vector3.new(0,WaveHeight,0) * math.noise(
				vertexPosition.X * WaveSize + currentTime + CharacterPos.Position.X, 
				vertexPosition.Y * WaveSize + currentTime, 
				vertexPosition.Z * WaveSize + currentTime + CharacterPos.Position.Z
			)
			
			EditableMesh:SetPosition(vertexId, newPosition)
		end
	end
	Object.Position = Vector3.new(CharacterPos.Position.X - (Offset * Width / 2), Object.Position.Y, CharacterPos.Position.Z - (Offset * Height / 2))
	task.wait()
end

Any help or suggestions will be thanked!

What happens when you remove the character’s position values from within the noise generation? Shouldn’t your time value and vertex position be sufficient enough?

The vertices on a meshpart use local positions, I found it would work if I used global positions by converting them instead of trying to use character position

Code:

            local vertexGlobalPos = Object.CFrame:PointToWorldSpace(vertexPosition * Object.Size / Object.MeshSize)
			local newPosition = vertexPosition + Vector3.new(0,WaveHeight,0) * math.noise(
				vertexGlobalPos.X * WaveSize + currentTime, 
				vertexGlobalPos.Y * WaveSize + currentTime, 
				vertexGlobalPos.Z * WaveSize + currentTime
			)
1 Like

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