Scrolling Game Development Kit Forum
SGDK Version 1 => Help/FAQ => Topic started by: Superjeep3 on 2005-09-15, 10:15:38 AM
-
Heya all, have another little question for ya. I have configured the controls to enable a joystick, and have used the scripting wizard for my weapon fire buttons. The fire buttons work fine on the joystick, but I wanted the player jump to be a button on the right side of the controller, and not on the left direction pad. I did the scripting wizard to make one of the buttons jump, and in the game it does, but it does not jump the full height of the player. What am I doing wrong?
-
The jump height is based on the "Jump Height" setting in the "Motion" tab of the "Sprites" dialog.
You can see this in the script where it says
.DY = - .rDef.Template.JumpHeight
Which is basically setting the y velocity of the player sprite to the (negative, so it goes up instead of down) jump height (set in the sprites dialog) of the player sprite.
How high the player actually jumps is based on the jump height (which is an initial velocity) and the gravity (which is a constant acceleration in the opposite direction). So if you really want it to jump exactly the height of the player, you would have to take the equation
x = x0 + v0(t) + 1/2*at^2
Knowing the initial velocity (v0), the initial x position (x0, which we can assume is 0, since it's relative to the ground in this case) and the acceleration (a, which is gravity). Graph this for x and t and you would see the change in height over time after a jump, and so you could change the variables until the max value of the parabola is equal to the height of the player.
Or, you know, just play around with it and get it about right. Which ever.
-
The problem is not that the player does not jump high enough. The problem is that when we set up the controls config to enable joystick, the button we set up for jump only makes the player sprite "bunny hop". Pressing up on the controller will make the player sprite jump the full length, but the button (same button setup as the up key) will not.
-
First of all, make sure that your joy-stick works propperly (it may be that auto-fire is turned on or something else is interfering). This, however, is probably not the problem.
Try a few debugging things. Continuously output the dy of the player sprite (using the Debugging Script (http://gamedev.comdel.net/viewtopic.php?t=559)), and see if it's set to zero as soon as you let go of the button, or what's going on.
-
Are you possibly using an old version of the scripting wizard that might be doing this:
.DY = - .rDef.Template.MoveSpeed
instead of this:
.DY = - .rDef.Template.JumpHeight
-
I am using version 1.4.5, as I am a student in at the Guildhall. Any ideas? The gameplay is better with a controller.
-
Maybe you could just paste the piece of script code that does the jump here... I can't be sure the scripting wizard with 1.4.5 got it right. I've been known to distribute GameDev for years at a time with the wrong version of the scripting wizard, and nobody noticing. :o
-
here is all of it, it is not that long
Dim nExpectCount
Dim nShot0Count
Dim arBtn0Shots(2)
Dim nShot2Count
Dim arBtn2Shots(0)
Dim nShot3Count
Dim arBtn3Shots(1)
Sub Player_OnControllerMove(OldActions, NewActions)
If (Not OldActions) And NewActions And ACTION_BUTTON1 Then DoFireButton0
If (Not OldActions) And NewActions And ACTION_BUTTON3 Then DoFireButton2
If (Not OldActions) And NewActions And ACTION_BUTTON4 Then DoFireButton3
End Sub
Sub RecountShots()
Dim nSIdx, nLIdx
With ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer
nSIdx = 0
Do While nSIdx < nShot0Count
For nLIdx = 0 to .SpriteCount - 1
If arBtn0Shots(nSIdx) Is .Sprite(nLIdx) Then
Exit For
End If
Next
If nLIdx >= .SpriteCount Then
Set arBtn0Shots(nSIdx) = arBtn0Shots(nShot0Count - 1)
nShot0Count = nShot0Count - 1
Else
nSIdx = nSIdx + 1
End If
Loop
nSIdx = 0
Do While nSIdx < nShot2Count
For nLIdx = 0 to .SpriteCount - 1
If arBtn2Shots(nSIdx) Is .Sprite(nLIdx) Then
Exit For
End If
Next
If nLIdx >= .SpriteCount Then
Set arBtn2Shots(nSIdx) = arBtn2Shots(nShot2Count - 1)
nShot2Count = nShot2Count - 1
Else
nSIdx = nSIdx + 1
End If
Loop
nSIdx = 0
Do While nSIdx < nShot3Count
For nLIdx = 0 to .SpriteCount - 1
If arBtn3Shots(nSIdx) Is .Sprite(nLIdx) Then
Exit For
End If
Next
If nLIdx >= .SpriteCount Then
Set arBtn3Shots(nSIdx) = arBtn3Shots(nShot3Count - 1)
nShot3Count = nShot3Count - 1
Else
nSIdx = nSIdx + 1
End If
Loop
nExpectCount = .SpriteCount
End With
End Sub
Sub RemoveShot(Spr)
Dim nIdx
With ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer
For nIdx = 0 to .SpriteCount - 1
If .Sprite(nIdx) Is Spr Then .RemoveSprite(nIdx) : Exit Sub
Next
End With
End Sub
Function GetStateDeltas(DX, DY)
With ProjectObj.GamePlayer.PlayerSprite
Select Case .rDef.Template.StateType
Case STATE_SINGLE
If Abs(DX) + Abs(DY) > 1 Then
DX = .DX / (Abs(.DX) + Abs(.DY))
DY = .DY / (Abs(.DX) + Abs(.DY))
Else
If Abs(DX) + Abs(DY) < 1 Then DX = 0 : DY = -1
End If
Case STATE_LEFT_RIGHT
DY = 0
If (.CurState Mod 2) = 0 Then DX = -1 Else DX = 1
Case STATE_8_DIRECTION
Select Case (.CurState Mod 8)
Case 0 : DX = 0 : DY = -1
Case 1 : DX = 1 : DY = -1
Case 2 : DX = 1 : DY = 0
Case 3 : DX = 1 : DY = 1
Case 4 : DX = 0 : DY = 1
Case 5 : DX = -1 : DY = 1
Case 6 : DX = -1 : DY = 0
Case 7 : DX = -1 : DY = -1
End Select
Case Else
DX = Cos((.CurState Mod 36) * 3.14159 / 18)
DY = -Sin((.CurState Mod 36) * 3.14159 / 18)
End Select
End With
End Function
Sub Player_OnAfterMoveSprites
Dim nIdx, VLeft, VTop, VRight, VBottom, VDat
With ProjectObj.GamePlayer
VLeft = .MapScrollX
VTop = .MapScrollY
VRight = VLeft + .rMap.ViewWidth
VBottom = VTop + .rMap.ViewHeight
End With
If nExpectCount <> ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer.SpriteCount Then RecountShots
nIdx = 0
Do While nIdx < nShot0Count
With arBtn0Shots(nIdx)
If .X < VLeft Or .X > VRight Or .Y < VTop Or .Y > VBottom Or (.DX = 0 And .DY = 0) Then
RemoveShot arBtn0Shots(nIdx)
Set arBtn0Shots(nIdx) = arBtn0Shots(nShot0Count - 1)
nShot0Count = nShot0Count - 1
nExpectCount = nExpectCount - 1
Else
nIdx = nIdx + 1
End if
End With
Loop
If nExpectCount <> ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer.SpriteCount Then RecountShots
nIdx = 0
Do While nIdx < nShot2Count
With arBtn2Shots(nIdx)
If .X < VLeft Or .X > VRight Or .Y < VTop Or .Y > VBottom Or (.DX = 0 And .DY = 0) Then
RemoveShot arBtn2Shots(nIdx)
Set arBtn2Shots(nIdx) = arBtn2Shots(nShot2Count - 1)
nShot2Count = nShot2Count - 1
nExpectCount = nExpectCount - 1
Else
nIdx = nIdx + 1
End if
End With
Loop
If nExpectCount <> ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer.SpriteCount Then RecountShots
nIdx = 0
Do While nIdx < nShot3Count
With arBtn3Shots(nIdx)
If .X < VLeft Or .X > VRight Or .Y < VTop Or .Y > VBottom Or (.DX = 0 And .DY = 0) Then
RemoveShot arBtn3Shots(nIdx)
Set arBtn3Shots(nIdx) = arBtn3Shots(nShot3Count - 1)
nShot3Count = nShot3Count - 1
nExpectCount = nExpectCount - 1
Else
nIdx = nIdx + 1
End if
End With
Loop
End Sub
Sub DoFireButton0()
Dim NewSpr, DX, DY
If nShot0Count >= 3 Then Exit Sub
If ProjectObj.GamePlayer.InvQuantityOwned(2) < 2 Then Exit sub
ProjectObj.GamePlayer.InvQuantityOwned(2) = ProjectObj.GamePlayer.InvQuantityOwned(2) - 2
Set NewSpr = ProjectObj.GamePlayer.rMap.SpriteDefs("pulsar_laser").MakeInstance
Set arBtn0Shots(nShot0Count) = NewSpr
nShot0Count = nShot0Count + 1
With ProjectObj.GamePlayer.PlayerSprite
.rDef.rLayer.AddSprite HostObj.AsObject(NewSpr)
nExpectCount = nExpectCount + 1
NewSpr.X = .X + (.Width - NewSpr.Width) / 2
NewSpr.Y = .Y + (.Height - NewSpr.Height) / 2
GetStateDeltas DX, DY
NewSpr.DX = DX * NewSpr.rDef.Template.MoveSpeed
NewSpr.DY = DY * NewSpr.rDef.Template.MoveSpeed
If NewSpr.rDef.Template.StateCount = 36 Then NewSpr.CurState = RectToPolarState(DX, DY)
ProjectObj.MediaMgr.Clip("pulsar").Play
End With
End Sub
Sub DoFireButton2()
Dim NewSpr, DX, DY
If nShot2Count >= 1 Then Exit Sub
If ProjectObj.GamePlayer.InvQuantityOwned(2) < 3 Then Exit sub
If ProjectObj.GamePlayer.InvQuantityOwned(10) < 1 Then Exit sub
ProjectObj.GamePlayer.InvQuantityOwned(2) = ProjectObj.GamePlayer.InvQuantityOwned(2) - 3
Set NewSpr = ProjectObj.GamePlayer.rMap.SpriteDefs("plasma_rifle").MakeInstance
Set arBtn2Shots(nShot2Count) = NewSpr
nShot2Count = nShot2Count + 1
With ProjectObj.GamePlayer.PlayerSprite
.rDef.rLayer.AddSprite HostObj.AsObject(NewSpr)
nExpectCount = nExpectCount + 1
NewSpr.X = .X + (.Width - NewSpr.Width) / 2
NewSpr.Y = .Y + (.Height - NewSpr.Height) / 2
GetStateDeltas DX, DY
NewSpr.DX = DX * NewSpr.rDef.Template.MoveSpeed
NewSpr.DY = DY * NewSpr.rDef.Template.MoveSpeed
If NewSpr.rDef.Template.StateCount = 36 Then NewSpr.CurState = RectToPolarState(DX, DY)
ProjectObj.MediaMgr.Clip("plasma_rifle").Play
End With
End Sub
Sub DoFireButton3()
Dim NewSpr, DX, DY
If nShot3Count >= 2 Then Exit Sub
If ProjectObj.GamePlayer.InvQuantityOwned(2) < 2 Then Exit sub
If ProjectObj.GamePlayer.InvQuantityOwned(4) < 1 Then Exit sub
ProjectObj.GamePlayer.InvQuantityOwned(2) = ProjectObj.GamePlayer.InvQuantityOwned(2) - 2
Set NewSpr = ProjectObj.GamePlayer.rMap.SpriteDefs("freeze_ray").MakeInstance
Set arBtn3Shots(nShot3Count) = NewSpr
nShot3Count = nShot3Count + 1
With ProjectObj.GamePlayer.PlayerSprite
.rDef.rLayer.AddSprite HostObj.AsObject(NewSpr)
nExpectCount = nExpectCount + 1
NewSpr.X = .X + (.Width - NewSpr.Width) / 2
NewSpr.Y = .Y + (.Height - NewSpr.Height) / 2
GetStateDeltas DX, DY
NewSpr.DX = DX * NewSpr.rDef.Template.MoveSpeed
NewSpr.DY = DY * NewSpr.rDef.Template.MoveSpeed
If NewSpr.rDef.Template.StateCount = 36 Then NewSpr.CurState = RectToPolarState(DX, DY)
ProjectObj.MediaMgr.Clip("freeze_ray").Play
End With
End Sub
Function RectToPolarState(X, Y)
Dim Angle, Pi
Pi = 3.14159
If X <> 0 Then
Angle = Atn(-Y / X)
Else
Angle = -(Pi / 2) * Sgn(Y)
End If
If X < 0 Then
Angle = Pi + Angle
ElseIf Y > 0 Then
Angle = Pi * 2 + Angle
End If
RectToPolarState = ((Angle * 18) / Pi) Mod 36
End Function
HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16
-
the smiley face = 8 so 1smileyface is really 18
-
That's still longer than I wanted. But I can see where you'd have trouble finding the piece of the script that handles jumping. It doesn't look like any button is set up to jump in that script. You have 3 buttons for 3 kinds of shooting defined, and that's it as far as I can tell.
-
that is the code generated from the four buttons, one being jump.
-
There is absolutely nothing in that code that makes the player jump. Change this:
Sub Player_OnControllerMove(OldActions, NewActions)
If (Not OldActions) And NewActions And ACTION_BUTTON1 Then DoFireButton0
If (Not OldActions) And NewActions And ACTION_BUTTON3 Then DoFireButton2
If (Not OldActions) And NewActions And ACTION_BUTTON4 Then DoFireButton3
End Sub
to this:
Sub Player_OnControllerMove(OldActions, NewActions)
If (Not OldActions) And NewActions And ACTION_BUTTON2 Then
With ProjectObj.GamePlayer.PlayerSprite
If (.rDef.SolidTest(.X, .Y + .Height) Or .rDef.SolidTest(.X + .Width - 1, .Y + .Height)) Or (Not .pRideOnRef Is Nothing) Then
.DY = - .rDef.Template.JumpHeight
End If
End With
End If
If (Not OldActions) And NewActions And ACTION_BUTTON1 Then DoFireButton0
If (Not OldActions) And NewActions And ACTION_BUTTON3 Then DoFireButton2
If (Not OldActions) And NewActions And ACTION_BUTTON4 Then DoFireButton3
End Sub
-
After running the scripting wizard myself, I see that, when attempting to recreate your code, I do indeed get:
Sub Player_OnControllerMove(OldActions, NewActions)
If (Not OldActions) And NewActions And ACTION_BUTTON1 Then DoFireButton0
With ProjectObj.GamePlayer.PlayerSprite
If (Not OldActions) And NewActions And ACTION_BUTTON2 Then
If (.rDef.SolidTest(.X, .Y + .Height) Or .rDef.SolidTest(.X + .Width - 1, .Y + .Height)) Or (Not .pRideOnRef Is Nothing) Then
.DY = - .rDef.Template.JumpHeight
End If
End If
End With
If (Not OldActions) And NewActions And ACTION_BUTTON3 Then DoFireButton2
If (Not OldActions) And NewActions And ACTION_BUTTON4 Then DoFireButton3
End Sub
I don't know what happened to yours, but it seems like either it was deleted, or you forgot to actually define that button to jump in the scripting wizard.
-
Thanx for fixing it for us, but we changed it to use the up direction on the pad, which I think is default. It helped us though because we ended up having to add a button function that took up the button we were going to use for jump. But, again, thanx.