Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Trying to get the perfect "jump" script

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
Baconlabs
PURPLE IS MANLY




Joined: 15 Mar 2009
Posts: 335
Location: Tennessee

PostPosted: Thu Jun 04, 2009 10:45 pm    Post subject: Trying to get the perfect "jump" script Reply with quote

For my game "Viridia," jumping is important, and I absolutely must not have any bugs when the main character uses this action. I've been at this for a good deal of hours and I need help ironing out the flaws.

Here's what I've come up with. There are 4 jump scripts, one for each direction; they're pretty much the same, so I'll only list one. In order to activate the script, the player runs onto an invisible NPC that triggers the jump script.
This is somewhat long because there is also a 4-frame animation that is supposed to run along with the jump.
Code:
plotscript,JumpL,begin
   if,begin
   key is pressed (key:left)
   and
   key is pressed (key:Z)
   #Z is the designated running key.
   end
   then,begin
   suspend hero walls
   suspend player
   set hero speed (me,5)
   set hero picture (me,9)
   set hero frame (me,0)
   wait (3)
   walk hero (me,left,3)
   set hero frame (me,1)
   set hero z (me,5)
   wait (2)
   set hero direction (me,up)
   set hero frame (me,0)
   set hero z (me,8)
   wait (3)
   set hero frame (me,1)
   set hero z (me,4)
   wait (3)
   set hero direction (me,left)
   set hero frame (me,0)
   set hero z (me,0)
   wait (3)
   set hero speed (me,4)
   set hero picture (me,5)
   resume hero walls
   resume player
   end
end


Things that went right:
-Compiles properly every time in hspeak
-4-frame animation (and Hero Z, on left/right/up jumps) work properly and look fine.

Things that went wrong (bugs):
-The player continues walking after "landing", but doesn't actually move, and doesn't respond - as if the "resume player" line was ignored.
-I tried fixing the above with "walk hero (me,direction,0)" in each script. After a successful jump, though, no more "jump" NPCs can be activated, so I removed it.

If any of you scripting gurus out there can help me out, I'd be most obliged.
Back to top
View user's profile Send private message
Spoon Weaver




Joined: 18 Nov 2008
Posts: 421
Location: @home

PostPosted: Thu Jun 04, 2009 10:54 pm    Post subject: Reply with quote

Quote:
-I tried fixing the above with "walk hero (me,direction,0)" in each script. After a successful jump, though, no more "jump" NPCs can be activated, so I removed it.


If this was the only way you got it working, I suggest putting it back like this. The problem sounds like you're activating the script with a one time use NPC. Make it not a one time use NPC.


OTHERWISE, you could also try extending the wait commands. The problem sounds like your hero is stuck in a wall. giving him a little extra time to "suspend walls" might do the trick.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Baconlabs
PURPLE IS MANLY




Joined: 15 Mar 2009
Posts: 335
Location: Tennessee

PostPosted: Thu Jun 04, 2009 11:05 pm    Post subject: Reply with quote

Spoon Weaver wrote:
OTHERWISE, you could also try extending the wait commands. The problem sounds like your hero is stuck in a wall. giving him a little extra time to "suspend walls" might do the trick.


Well, I'll be danged! I was exactly one tick off.
By changing the last wait command from 3 to 4, everything works fine now. Funny, I didn't think it would be that simple.

Now I've just got to be careful about two things:
Keeping each gap the right size, and leaving enough room to run.

Thanks much!
Back to top
View user's profile Send private message
Spoon Weaver




Joined: 18 Nov 2008
Posts: 421
Location: @home

PostPosted: Thu Jun 04, 2009 11:55 pm    Post subject: Reply with quote

Baconlabs wrote:
Spoon Weaver wrote:
OTHERWISE, you could also try extending the wait commands. The problem sounds like your hero is stuck in a wall. giving him a little extra time to "suspend walls" might do the trick.


Well, I'll be danged! I was exactly one tick off.
By changing the last wait command from 3 to 4, everything works fine now. Funny, I didn't think it would be that simple.

Now I've just got to be careful about two things:
Keeping each gap the right size, and leaving enough room to run.

Thanks much!


Glad I could help.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Baconlabs
PURPLE IS MANLY




Joined: 15 Mar 2009
Posts: 335
Location: Tennessee

PostPosted: Fri Jun 05, 2009 1:40 am    Post subject: Reply with quote

After experimenting a bit more, I found another bug that I could avoid by just placing NPCs a bit more carefully, but I'll talk about it anyway.

If, while jumping, I pass over another invisible jump NPC and hit the right keys, the first jump will be overwritten with the second.
After landing, the character is about 1/2 block off-center and no more jump NPCs can be used. I'll have to keep this in mind when playtesting.

Is there something along the lines of "suspend keyboard" in the Plotscripting dictionary? That would fix the problem instantly, but it doesn't seem to exist.
Back to top
View user's profile Send private message
Spoon Weaver




Joined: 18 Nov 2008
Posts: 421
Location: @home

PostPosted: Fri Jun 05, 2009 2:20 am    Post subject: Reply with quote

What you could do is have the script check to see if a global variable (lets call it jumpvar) equals 0. then when the script starts make the variable equal 1 ( or whatever number you want). then at the end have it be returned to 0.

Do you follow me?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Baconlabs
PURPLE IS MANLY




Joined: 15 Mar 2009
Posts: 335
Location: Tennessee

PostPosted: Fri Jun 05, 2009 1:19 pm    Post subject: Reply with quote

Well, there we go. Global variables work!
For now, this script is bug-proof.

Here's the revised edition.

Code:
plotscript,JumpL,begin
   if,begin
   key is pressed (key:left)
   and
   key is pressed (key:Z)   
   and
   jumpvar == 0
   end
   then,begin
   suspend hero walls
   suspend player
   set variable(jumpvar,1)
   set hero speed (me,5)
   set hero picture (me,9)
   set hero frame (me,0)
   wait (3)
   walk hero (me,left,3)
   set hero frame (me,1)
   set hero z (me,5)
   wait (2)
   set hero direction (me,up)
   set hero frame (me,0)
   set hero z (me,8)
   wait (3)
   set hero frame (me,1)
   set hero z (me,4)
   wait (3)
   set hero direction (me,left)
   set hero frame (me,0)
   set hero z (me,0)
   wait (4)
   set hero speed (me,4)
   set hero picture (me,5)
   set variable(jumpvar,0)
   resume hero walls
   resume player
   end
end
Back to top
View user's profile Send private message
Spoon Weaver




Joined: 18 Nov 2008
Posts: 421
Location: @home

PostPosted: Fri Jun 05, 2009 2:02 pm    Post subject: Reply with quote

Glad I could help again! I look forward to your game.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Mon Jun 15, 2009 7:23 am    Post subject: Reply with quote

Since you did say 'perfect'...
That jumping animation isn't as smooth as it could be: you only update the z coordinate every few ticks. You can use a for loop to update it every tick. Here's a script that does a parabolic (realistic) jump:
http://www.castleparadox.com/ohr/viewtopic.php?p=19274#19274
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group