Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Snake tail effect using joints
Started by DevilDev Aug 24 2019 06:54 PM

2 replies to this topic
trail tail joints snake

Best Answer roaminggamer , 24 August 2019 - 09:31 PM

Don't use joints, linked to joints, linked to joints, ...  That is too heavy (calculation wise) and won't ever behave nicely. 

 

Use enterframe listener(s).

 

 

Download entire RGFreeStuff (https://github.com/roaminggamer/RG_FreeStuff) and look here:

RG_FreeStuff\AskEd\2015\05\followTheLeader

 

or download files from here, one by one:

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015/05/followTheLeader

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

DevilDev

[GLOBAL: userInfoPane.html]
DevilDev
  • Enthusiast

  • 74 posts
  • Corona SDK

I created trail using joints.But I when I move it,it starts shaking weirdly after a while.

It is not steady or smooth as in snake vs blocks.

Code is below


local centerX = display.contentCenterX
local centerY = display.contentCenterY
local _W = display.contentWidth
local _H = display.contentHeight

local physics = require("physics")
physics.start()

local sg = display.newGroup()
local xc = display.contentCenterX
local yc = display.contentCenterY
local w = display.contentWidth
local h = display.contentHeight
math.randomseed(os.clock())
local r = math.random
physics.setDrawMode("hybrid")
local xv, px, pb, ccv
for i = 1, 10 do
    xv = display.newRect(centerX, centerY, 30, 30)
    xv.x = xc
    if i > 1 then
        physics.addBody(xv, "dynamic", {density = 2.0, friction = 0, bounce = 0})
        xv.isSleepingAllowed = false
        xv.y = px + xv.contentHeight
        local c = physics.newJoint("pivot", pb, xv, pb.x, pb.y)
    else
        physics.addBody(xv, "static", {density = 2.0, friction = 0, bounce = 0})
        xv.y = yc
        ccv = xv
    end
    px = xv.y
    pb = xv
end
local function moveTheSnake(event)
    ccv.x = event.x
end

Runtime:addEventListener("touch", moveTheSnake)

Any suggestions?

Thanks!



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,588 posts
  • Corona SDK

  Best Answer

Don't use joints, linked to joints, linked to joints, ...  That is too heavy (calculation wise) and won't ever behave nicely. 

 

Use enterframe listener(s).

 

 

Download entire RGFreeStuff (https://github.com/roaminggamer/RG_FreeStuff) and look here:

RG_FreeStuff\AskEd\2015\05\followTheLeader

 

or download files from here, one by one:

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015/05/followTheLeader


  • nick_sherman and DevilDev like this

[TOPIC: post.html]
#3

DevilDev

[GLOBAL: userInfoPane.html]
DevilDev
  • Enthusiast

  • 74 posts
  • Corona SDK

thanks RG!




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: trail, tail, joints, snake