Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the motorSpeed of the Wheel Joint always being set to a value of 1 #701

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kan6868
Copy link
Contributor

@kan6868 kan6868 commented May 4, 2024

Issue:
https://github.com/coronalabs/corona/assets/70838508/8b2cc0b4-dc26-49f5-b014-4bd296f5c313

Fixed:
https://github.com/coronalabs/corona/assets/70838508/e76b467e-bd65-404b-a840-6dcfa0e116b1

Code - Test:

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

local textWheel = display.newText("Wheel Joint", 100, 50, nil, 20)

local textPivot = display.newText("Pivot Joint", 300, 50, nil, 20)

local wheel1 = display.newRect(100, 220, 30, 30)
physics.addBody(wheel1, "dynamic", { bounce = 0, density = 1 })

local body = display.newRect(100, 150, 30, 30)
physics.addBody(body, "static", { bounce = 0, density = 1 })
body:setFillColor(1, 0, 1)

local ground = display.newRect(display.contentCenterX, display.actualContentHeight, display.actualContentWidth, 100)

physics.addBody(ground, "static", { bounce = 0 })

local wheel2 = display.newRect(300, 220, 30, 30)
physics.addBody(wheel2, "dynamic", { bounce = 0, density = 1 })

local body2 = display.newRect(300, 150, 30, 30)
physics.addBody(body2, "static", { bounce = 0, density = 1 })
body2:setFillColor(1, 0, 1)

local joint = physics.newJoint("wheel", body, wheel1, wheel1.x, wheel1.y, 0, 10)
joint.springFrequency = 15
joint.springDampingRatio = 0.5

joint.isMotorEnabled = true

joint.motorSpeed = 1000
joint.maxMotorTorque = 1000000

local joint2 = physics.newJoint("pivot", body2, wheel2, wheel2.x, wheel2.y)

joint2.isMotorEnabled = true
joint2.motorSpeed = 1000

joint2.maxMotorTorque = 1000000

@kan6868 kan6868 requested a review from Shchvova as a code owner May 4, 2024 07:32
@kan6868 kan6868 changed the title Fix the motorSpeed of the Wheel Joint always being set to a value of 1 Fix the motorSpeed of the Wheel Joint always being set to a value of 1, getReactionForce not returning value according to inverse delta time. May 5, 2024
@kan6868 kan6868 changed the title Fix the motorSpeed of the Wheel Joint always being set to a value of 1, getReactionForce not returning value according to inverse delta time. Fix the motorSpeed of the Wheel Joint always being set to a value of 1 May 5, 2024
@kan6868
Copy link
Contributor Author

kan6868 commented May 5, 2024

I had some confusion about runtime.GetFPS.
It's similar to 1 / (physics.GetTimeStep() * physics.GetTimeScale()).
So I reverted the commit 0c869d3.

@zero-meta
Copy link

I think motorSpeed for Wheel Joint should be radians per seconds, the same as the Revolute Joint.

if ( lua_isnumber( L, 3 ) )
{
	Rtt_Real valueRadians = Rtt_RealDegreesToRadians( luaL_toreal( L, 3 ) );
	joint->SetMotorSpeed( Rtt_RealToFloat( valueRadians ) );
}

@davidearle
Copy link

Nice job on the fix! I had a PR (#641) suggesting a solution for the axis issue. Glad to see progress on this.

@kan6868
Copy link
Contributor Author

kan6868 commented May 6, 2024

OK, I'll do some tests on it.
And push a new commit.

@kan6868
Copy link
Contributor Author

kan6868 commented May 6, 2024

Nice job on the fix! I had a PR (#641) suggesting a solution for the axis issue. Glad to see progress on this.

Your solution about the axis is correct when normalizing values to 1 or -1.

I'm also encountering an issue with the axis of the wheel joint; it seems more like a piston force along the axis.

However, this might necessitate changes to the previous project's attributes: springDampingRatio and springFrequency.

We need some opinions from @Shchvova , and it should be in a new pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants