Need help with short code!
Hi. it isn't any complicated, looking perfect but doesn't work for hours.
So I really need your helps..
There is an actor A, Leftbutton, Rightbutton.
At the beginning actor A has Velocity X,Y 100 100.
rightbutton's rule is -------
1.when key x is pressed, if attribute is scene.background.A.Motion.LinearVelocity X > 0,
S.B.A.M.LinearVelocity Y -> S.B.A.M.Linear Velocity Y*-1
and
2.when Key x is pressed, if attribute S.B.A.M.LinearVelocity X < 0,
S.B.A.M.LinearVelocity X -> S.B.A.M.Linear Velocity X*-1
leftbutton's rule is ---------
1.when key z is pressed, if attribute is scene.background.A.Motion.LinearVelocity X > 0,
S.B.A.M.LinearVelocity X -> S.B.A.M.Linear Velocity X*-1
and
2.when Key z is pressed, if attribute S.B.A.M.LinearVelocity X < 0,
S.B.A.M.LinearVelocity Y -> S.B.A.M.Linear Velocity Y*-1
A moves only diagonally.
If A moves to the right, and if you press right button, it should change it's Y velocity and keep moving to the right.
But if A moves to the right and you press left button, then it should change it's X velocity but Y velocity does not change.
However, result is if A is moving to the right and click Leftbutton, it changes X velocity but also changes its Y Velocity too.
A moving to the left and click rightbutton, it should change only its X velocity but this way it also changes its Y velocity too.
Anyone knows the solution please?
Comments
What does this . . .
->
. . . mean ?
What is . . .
S.B.A.M
?
@Socks
SBAM!!! It's like you didn't quite see it coming... sssss.... BAM!!! SBAM.
I think -> is just an arrow. So this:
S.B.A.M.LinearVelocity Y -> S.B.A.M.Linear Velocity Y*-1
Probably means Change Attribute LinearVelocity.Y to LinearVelocity.Y*(-1)
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thank you, that's cleared it up
Ah! Yes, that makes more sense now. It makes negative numbers positive and positive numbers negative. Not sure what BAM!! (kapow!) controls, maybe it it controls the actor called 'A' ?
(did I ever mention I have zero interpretation skills!)
S.B.A.M means Scene.Background.A.Motion. and -> is Change attribute to .
Sorry I thought people would understand but my mistake!
It's a little confusing how you said "press left button" but your rule condition is actually a key press (z). So I'll stick to key presses.
What's happening is that the Key Press is still in effect after you change the X velocity of the actor.
Your rules basically say this (assuming the actor is moving to the right):
Left button:
When z key is pressed
When velocityX > 0
Change velocity X to -X
When velocityX < 0
Change velocity Y to -Y
So... when you "click" the Left button actor by pressing the 'z' key, the first rule is triggered since velocityX is positive. But while the key is held down (even for a half second or whatever), the second rule becomes true now that velocityX is negative and so therefore velocityY is switched.
I believe the fix for this -- but I haven't tested it -- is...
Left button:
When z key is pressed
When velocityX > 0
Change velocity X to -X
Otherwise
When velocityX < 0
Change velocity Y to -Y
That should prevent the second sub-rule from triggering unless the 'z' key is released and then pressed a second time (e.g. when velocityX is negative).
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thank you so much for your help! But unfortunately it didn't work ..
Everything would be perfect but because of this little problem Im stuck.
Do you have any other idea to fix it? I keep thinking about it since yesterday morning but just my head hurts and nothing's getting better.
Yep, post a download link for the project file and someone can take a look at your logic.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User