Physics Button

Get help using Construct 2

Post » Fri Aug 03, 2012 12:40 am

How can I make a button that will push down and trigger an event when a specific amount of weight is on top of it? I already have a system in place for triggering an event, but no matter what I try the buttons don't always work like they should.

When nothing is on top of the button, it should move to/stay at its original position. When something heavy enough is on top of the button, it should move down 32 pixels. When something not heavy enough is on top of the button, it should move down a realistic amount. Whenever it moves, it should move smoothly.
B
25
S
8
G
8
Posts: 71
Reputation: 5,307

Post » Fri Aug 03, 2012 1:08 am

Are you doing this using the physics behaviour?
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Fri Aug 03, 2012 2:00 am

Here's a way to do it by simply moving the button based on a "weight" variable in the box objects. You could also set the height of it if you can't hide it behind another object like I do in this example.

PhysicsTrigger.capx (r99)Nimtrix2012-08-03 02:01:22
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Fri Aug 03, 2012 4:11 am


I played with nimtrix's and made the button a physics object too

https://dl.dropbox.com/u/53374990/phystrig.capx keepee2012-08-03 04:11:54
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Fri Aug 03, 2012 5:12 am

@Nimtrix Thank you! It works now.

@keepee I got an error when opening your capx.


---------------------------
Error loading project
---------------------------
Failed to open project 'C:\Users\Nick\Downloads\phystrig.capx--':

Error document empty.

The file may be invalid. Try checking the file in a text editor (projects are saved in XML format).
---------------------------
OK   
---------------------------
B
25
S
8
G
8
Posts: 71
Reputation: 5,307

Post » Fri Aug 03, 2012 6:49 am

@zephlon
odd...it opens fine here. Can anyone else confirm this?


anyway.. this is all I did:
https://dl.dropbox.com/u/53374990/phystrig/index.htmlkeepee2012-08-03 06:54:30
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Sat Aug 04, 2012 12:42 am

I removed the -- from the file extension and it opened as it should.

Thank you, keepee! That is exactly what I was looking for.

Only problem after I implemented it into my game is that when you place heavy objects on the button, it bounces causing the doors to open and close repeatedly.
B
25
S
8
G
8
Posts: 71
Reputation: 5,307

Post » Sat Aug 04, 2012 6:06 am

@Zephlon, try increasing the buttons 'linear damping' quite a lot. All this does is slow the objects velocity over the time.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683


Return to How do I....?

Who is online

Users browsing this forum: Ethan, makkancs, Marxally, Naightwolf, pierre244 and 15 guests