Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make a piano lid lift slowly
Cryaotic Offline
Senior Member

Posts: 369
Threads: 13
Joined: Oct 2010
Reputation: 72
#1
How to make a piano lid lift slowly

As of right now I have the lid opening upon interaction with an object, it opens all the way after a jerky movement which is all fine and good, though I was going for a slowly moving effect which seems quite challenging to come by.

This is what I have currently:
PHP Code: (Select All)
void pianocoverlift1(string &in asEntity){    if(GetLocalVarInt("LiftDone") != 1){    SetLocalVarFloat("LiftBuildUp"0);    AddTimer ("LiftingPiano"0.50"LiftingPiano1");    AddTimer ("PianoLiftStop"4.5"PianoLiftStopFunc");}    else{        RemoveTimer("LiftingPiano");        }}
void LiftingPiano1(string &in asTimer){    if(GetLocalVarInt("LiftDone") != 1){    AddPropForce("pianocloset"0GetLocalVarFloat("LiftBuildUp"), 0"world");    AddTimer ("LiftingPiano"0.1"LiftingPiano1");    AddLocalVarFloat("LiftBuildUp"15);}}
void PianoLiftStopFunc(string &in asTimer){    if(asTimer=="PianoLiftStop"){    RemoveTimer("LiftingPiano");    RemoveTimer("LiftingPiano1");    }} 
Does anyone by chance have any idea of what I could do to make the effect more fluid and simply open as if the player's hand was slowly opening it instead of a jerky madness that is this?

Thank you kindly for any assistance!

(also I have no idea how to make the format of the code look good on the forum, it's being weird for me)

12-18-2011, 12:05 AM
Find
Khyrpa Offline
Senior Member

Posts: 638
Threads: 10
Joined: Apr 2011
Reputation: 24
#2
RE: How to make a piano lid lift slowly

Well one thing that comes to mind would be to change the piano's type in the model editor from Lever to MoveObject and use SetMoveObjectState.
I guess it would make the piano un- interactable though.

Using something like you did there with lower values could make it seem more fluent. I would personally use ugly switch case function with a 100 cases, but thats just me.

12-18-2011, 12:31 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#3
RE: How to make a piano lid lift slowly

Try using SetLeverStuckState instead of AddPropForce.

(12-18-2011, 12:05 AM)Cryaotic Wrote: (also I have no idea how to make the format of the code look good on the forum, it's being weird for me)

(Stop using the WYSIWYG editor of the forums.)

Tutorials: From Noob to Pro
(This post was last modified: 12-18-2011, 01:10 AM by Your Computer.)
12-18-2011, 01:09 AM
Website Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#4
RE: How to make a piano lid lift slowly

Try this:
PHP Code: (Select All)
int pianoTick=0;
float fPianoStep=0.02f;
void PianoLift(string &in timer)
{
    
pianoTick++;
    if(
pianoTick 50) return;
    
SetLeverStuckState("pianonamehere"fPianoStep*pianoTickfalse);
    
AddTimer(""0.05f"PianoLift");


This loop repeats very quickly to constantly be adding a small upwards force to the lid. You'll definitely have to tweak values to get it right since I have no idea what force values you'll need. Initiate it by using a timer with a duration of 0.01f, so it basically triggers instantly. Also, replace pianonamehere with your piano's name. Don't change the _BodyLid suffix, that designates the entity body to apply the force to.



LATER EDIT: Well I was curious so I tried it out in-game. Doesn't work very well, even with a custom entity with modified properties. The reason being that the object has gravity so it just falls back down. It works for doors though. :3

I'll try more stuff later, I have a few ideas in mind. Ropes and stuff.

(This post was last modified: 12-18-2011, 02:03 AM by palistov.)
12-18-2011, 01:15 AM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#5
RE: How to make a piano lid lift slowly

That approach should work if you make the timestep small enough. Try 0.0166f (1/60).
(This post was last modified: 12-18-2011, 02:33 AM by Apjjm.)
12-18-2011, 02:32 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#6
RE: How to make a piano lid lift slowly

Unless i'm mistaken, SetLeverStuckState causes a smooth animation for the lever, so a looping timer is unnecessary. A value of -1 for the state should suffice.

Tutorials: From Noob to Pro
12-18-2011, 02:38 AM
Website Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#7
RE: How to make a piano lid lift slowly

@Apjjm - yeah I didn't try it with a very large range of values. Perhaps the step value of .02 was a little too long.

@Your Computer - I tried using a looping timer to set the stuck state progressively higher, but the lid doesn't move at all when using that function -- I think it's only used for keeping the lever at a state once it has been reached.

Maybe I'll give it another later, but there's always the option of separating the lid and piano meshes and using separate entities. That's usually the approach I take, but I didn't dig too deeply into the issue.

12-18-2011, 04:57 AM
Find
Cryaotic Offline
Senior Member

Posts: 369
Threads: 13
Joined: Oct 2010
Reputation: 72
#8
RE: How to make a piano lid lift slowly

(12-18-2011, 02:32 AM)Apjjm Wrote: That approach should work if you make the timestep small enough. Try 0.0166f (1/60).
This one actually worked quite well!

In the end I just changed the time between each loop to 0.0166f andthe force increase to .50 each loop - a really almost eerie effect because of how natural it does it.

Thanks for all those that chipped in! Definitely worked great. :]

12-19-2011, 01:30 AM
Find




Users browsing this thread: 1 Guest(s)