• Register a free account to view all forum content. Click here to create your own account.

Fluid Object Movement

spleenhook

New Member
Joined
Aug 7, 2018
Messages
2
Roblox
spleenhook
I'm trying to animate a fluid motion of a pet following me. Sorry if the code looks poorly constructed, I am new to Lua (however do have lots of experience programming in other languages). Essentially, the pet will follow but appears to stutter (just very slightly, but enough to upset the eye). This is an effect that is not replicated in all servers which contain pets or other moving objects. Here is the code for its movement (very simple currently, just meant to bounce up and down, twist a bit, and always look and move towards its destination):

Code:
repeat wait() until script.Parent.Owner.Value ~= "n/a"
print("Pet spawned for "..script.Parent.Owner.Value.."!")

local orientation = 0
local sway = 1

local pet
local destination
local owner
local speed

local function load()
    pet = script.Parent
    owner = game.Workspace[pet.Owner.Value]
    destination = owner.HumanoidRootPart.Position
    speed = pet.Speed
    
    pet.PetPart.Position = destination
    
    while true do
        runTick()
        wait()
    end
end

local function moveTick()
    if sway == 1 then
        orientation = orientation + 8
    else
        orientation = orientation - 8
    end
    if orientation > 90 then
        orientation = 85
        sway = -1
    end
    if orientation < -90 then
        orientation = -85
        sway = 1
    end
    local dx = destination.X - pet.PetPart.Position.X
    local dz = destination.Z - pet.PetPart.Position.Z
    local dist = math.sqrt(math.pow(dx, 2) + math.pow(dz, 2))
    
    -- Look at destination (Y) and twists on jump (X)
    pet.PetPart.Orientation = Vector3.new(20 * math.sin(math.pi*(orientation/180)), 270 + 180*(math.atan2(dx, dz)/math.pi), pet.PetPart.Orientation.Z)   

    -- Starts newVel with just the jump animation   
    local newVel = Vector3.new(pet.PetPart.Position.X, 17 + 0.5 * math.abs(math.sin(math.pi*(orientation/180))), pet.PetPart.Position.Z)
    
    -- If not too close, approaches destination
    if dist > 4 then
        newVel = newVel + speed.Value*Vector3.new(dx/dist, 0, dz/dist)
    end
    
    pet.PetPart.Position = newVel
end

function runTick()
    if pet == nil then
        return
    end
    moveTick()
    destination = owner.HumanoidRootPart.Position
end

load()
Once again, thanks!
 
Joined
Aug 7, 2018
Messages
283
Ratings
15
Roblox
Page42
Discord
Delwyn Zincghast#3185
Seeing how I don't know, how to read scripts, i'll just leave this, 'wut?".
 

LuaBanana

New Member
Joined
Jul 2, 2018
Messages
8
Roblox
TheluaBanana
I'm trying to animate a fluid motion of a pet following me. Sorry if the code looks poorly constructed, I am new to Lua (however do have lots of experience programming in other languages). Essentially, the pet will follow but appears to stutter (just very slightly, but enough to upset the eye). This is an effect that is not replicated in all servers which contain pets or other moving objects. Here is the code for its movement (very simple currently, just meant to bounce up and down, twist a bit, and always look and move towards its destination):

Code:
repeat wait() until script.Parent.Owner.Value ~= "n/a"
print("Pet spawned for "..script.Parent.Owner.Value.."!")

local orientation = 0
local sway = 1

local pet
local destination
local owner
local speed

local function load()
    pet = script.Parent
    owner = game.Workspace[pet.Owner.Value]
    destination = owner.HumanoidRootPart.Position
    speed = pet.Speed
   
    pet.PetPart.Position = destination
   
    while true do
        runTick()
        wait()
    end
end

local function moveTick()
    if sway == 1 then
        orientation = orientation + 8
    else
        orientation = orientation - 8
    end
    if orientation > 90 then
        orientation = 85
        sway = -1
    end
    if orientation < -90 then
        orientation = -85
        sway = 1
    end
    local dx = destination.X - pet.PetPart.Position.X
    local dz = destination.Z - pet.PetPart.Position.Z
    local dist = math.sqrt(math.pow(dx, 2) + math.pow(dz, 2))
   
    -- Look at destination (Y) and twists on jump (X)
    pet.PetPart.Orientation = Vector3.new(20 * math.sin(math.pi*(orientation/180)), 270 + 180*(math.atan2(dx, dz)/math.pi), pet.PetPart.Orientation.Z)  

    -- Starts newVel with just the jump animation  
    local newVel = Vector3.new(pet.PetPart.Position.X, 17 + 0.5 * math.abs(math.sin(math.pi*(orientation/180))), pet.PetPart.Position.Z)
   
    -- If not too close, approaches destination
    if dist > 4 then
        newVel = newVel + speed.Value*Vector3.new(dx/dist, 0, dz/dist)
    end
   
    pet.PetPart.Position = newVel
end

function runTick()
    if pet == nil then
        return
    end
    moveTick()
    destination = owner.HumanoidRootPart.Position
end

load()
Once again, thanks!
umm u look like u only know html
Post automatically merged:

I'm trying to animate a fluid motion of a pet following me. Sorry if the code looks poorly constructed, I am new to Lua (however do have lots of experience programming in other languages). Essentially, the pet will follow but appears to stutter (just very slightly, but enough to upset the eye). This is an effect that is not replicated in all servers which contain pets or other moving objects. Here is the code for its movement (very simple currently, just meant to bounce up and down, twist a bit, and always look and move towards its destination):

Code:
repeat wait() until script.Parent.Owner.Value ~= "n/a"
print("Pet spawned for "..script.Parent.Owner.Value.."!")

local orientation = 0
local sway = 1

local pet
local destination
local owner
local speed

local function load()
    pet = script.Parent
    owner = game.Workspace[pet.Owner.Value]
    destination = owner.HumanoidRootPart.Position
    speed = pet.Speed
  
    pet.PetPart.Position = destination
  
    while true do
        runTick()
        wait()
    end
end

local function moveTick()
    if sway == 1 then
        orientation = orientation + 8
    else
        orientation = orientation - 8
    end
    if orientation > 90 then
        orientation = 85
        sway = -1
    end
    if orientation < -90 then
        orientation = -85
        sway = 1
    end
    local dx = destination.X - pet.PetPart.Position.X
    local dz = destination.Z - pet.PetPart.Position.Z
    local dist = math.sqrt(math.pow(dx, 2) + math.pow(dz, 2))
  
    -- Look at destination (Y) and twists on jump (X)
    pet.PetPart.Orientation = Vector3.new(20 * math.sin(math.pi*(orientation/180)), 270 + 180*(math.atan2(dx, dz)/math.pi), pet.PetPart.Orientation.Z) 

    -- Starts newVel with just the jump animation 
    local newVel = Vector3.new(pet.PetPart.Position.X, 17 + 0.5 * math.abs(math.sin(math.pi*(orientation/180))), pet.PetPart.Position.Z)
  
    -- If not too close, approaches destination
    if dist > 4 then
        newVel = newVel + speed.Value*Vector3.new(dx/dist, 0, dz/dist)
    end
  
    pet.PetPart.Position = newVel
end

function runTick()
    if pet == nil then
        return
    end
    moveTick()
    destination = owner.HumanoidRootPart.Position
end

load()
Once again, thanks!
umm u look like u only know html
either way u might wanna look into this:

http://wiki.roblox.com/index.php?title=Making_a_Floating_sphere#Method_one:_BodyPosition
 
Joined
Aug 7, 2018
Messages
2
Roblox
spleenhook
Not sure what you are implying by the first comment. I actually do not know HTML, nor do I believe that is classifiable as a programming language, similar to Lua in that regard. The languages I was referring to were Java, (Node)JS, Python, R and Octave. My question referred to the latency of ROBLOX which is not answered in your response.

Thanks for trying to help though. Going to lock the thread (if I can, not sure what this forum permits). I realized this runs as smoothly as the motion I am attempting to draw inspiration from in ROBLOX.
 
Joined
Feb 11, 2018
Messages
68
Ratings
7
Roblox
peanutbutter12344
Discord
KBenster#8998
Your knowledge of other languages shows, but the only thing I can say is to check if its anchored.

Edit:
A velocity PVector should be added to the position, I think.
 
Joined
Jun 4, 2018
Messages
10
Roblox
proclet
Spleenhook, the code looks interesting. Definitely some things I haven's seen until now (for instance, did you perhaps mean "nil" instead of "n/a" ?) Not working at all for me, it gives an error message : "Owner is not a valid member of Part". Could I see your Explorer tree, please ?