Jump to content

Weighted Button powered by physics


reepblue
 Share

Go to solution Solved by reepblue,

Recommended Posts

I'm looking into ways to re-create my floor buttons I've used in the Vectronic Demo. I don't want to rely on triggers this time around but instead have it be reactive to live physics. Here is a rad picture of how I intend to do this,

image.png.c8ba6bd12569525879658e36aca44f73.png

The idea was to have a slider with a spring attached to prevent the slider joint from collapsing on itself. To test if the button was pressed, I would test the distance from the top model to the base entity. I've tried this with 4.5 and the top kept bouncing. The only thing that worked was using a Kinematic joint, but I couldn't lock it to an axis. I haven't tried this in months, but what would be the best way to go about this and is this do-able in the engine. I hate to ask for help without providing code, but I don't have my attempts anymore.

  • Like 1

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Also, if the button does not move around in the scene you can make the parent entity NULL. This doesn't really matter in terms of behavior but it might make life simpler.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • Solution

It's a start, might need adjusting later but this is great for VR push buttons.

function Script:Start()
	self.entity:SetMass(1)
	self.entity:SetGravityMode(false)
	local position=self.entity:GetPosition(true)
	self.joint=Joint:Slider(position.x,position.y,position.z,0,-20,0,self.entity,nil)
    self.joint:EnableLimits()
    self.joint:SetLimits(0,1) -- The lower the number, the shorter distance.
	self.joint:SetSpring(1000,1000,self.entity:GetMass())
end

function Script:UpdateWorld()
	if self.joint:GetAngle() >= 0.1 then
	System:Print(self.joint:GetAngle())
	end
end

 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Just putting this info here in-case someone looks this up:

Add an additional sub-step to prevent the spring from "freaking out" when down.
 

world->Update(2)

Current code that's working very nice.

function Script:Start()
	self.entity:SetMass(1)
	self.entity:SetGravityMode(false)
	local position=self.entity:GetPosition(true)
	self.joint=Joint:Slider(position.x,position.y,position.z,0,-20,0,self.entity,nil)
    self.joint:EnableLimits()
    self.joint:SetLimits(0,0.02)
	self.joint:SetFriction(1000,1000)
	self.joint:SetSpring(2500,2500,50)
end

function Script:UpdateWorld()
	if self.joint:GetAngle() >= 0.01 then
	System:Print(self.joint:GetAngle())
	end
end

 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...