Move to.
benjaminmage
Member Posts: 74
I have a box that would move from left to right, vice versa. But when i spam click, the box will fly out of the screen. Whats wrong? please help
Comments
Hey @benjaminmage,
this thread should answer your question:
http://forums.gamesalad.com/discussion/comment/533752#Comment_533752
Use the Interpolate behaviour instead.
Or constrain the actor's X position to: 248 *sin (self.time *181.45) +383
@Socks I tried the interpolate behaviour, it works perfectly fine until i dropped the timing to 0.1 seconds using linear function. And as for the Actor's X position, i dont quite get you.
Did you want the actor to move across the screen in a tenth of a second !?
In the initial screenshot of your code the actor is moving at 500 pps, the actor is moving through 496 pixels, therefore the duration should be around 1 second. In the second version it is moving at 1300 pps, which would be a duration of 0.38 seconds.
0.1 seconds duration = 4,960 pps !
@benjaminmage said:
Firstly, I just checked my numbers and they were out of whack, they should read:
248 *sin (self.time *181.45) +383
You don't need any of the other rules, none the rules that check the actor's position, just a single constrain behaviour, nothing else.
. . . .
P.S phrases like 'it works perfectly fine until . . .' are pretty mysterious if you are trying to help someone resolve an issue, it would be much more useful to know what does happens rather than what doesn't happen, it's like you are about to impart some useful information but decide not too for some reason !
It works perfectly fine until i dropped the timing to 0.1 seconds using linear function . . . at which point . . .'it zooms off the screen' . . . or . . . 'it starts wobbling back and forth' . . . or . . . 'it won't move at all' . . . or . . . 'It moves to the first position but then just stops' (etc) - hope that makes sense.
@Socks is a superhero, I tell ya!
Mathtap.com (Android) | Fridgemanager.com (Android) | Breakoutofspace.com (Android)
At last, the sock / superhero crossover I have been waiting for !
@Socks Oh my apologies anyway yes i want the actor to move across the screen in a tenth of a second. I was just trying the "move to" function at first to see if there is any problem before i decrease the timing.
Anyway, i tried constraining the actor's x to 248 *sin (self.time *181.45) +383 but it went to its first position which is the extreme right and then bounces back to somewhere in the middle. Literally somewhere because each time i preview it, it bounces to a different x position.
thanks btw!!
What you are doing is right, it should work even with a 0.1 duration, it might possibly be some kind of rounding error, one suggestion would be to use larger than and smaller than rather than equals . . . so rather than if x = 135 and if x = 631 try if x < 136 and if x > 630 (whilst still using 135 and 631 as your Interpolate/MoveTo targets)
Can you take a screenshot of the code for this ? Are you sure you have no other rules running, just a single constrain behaviour ?
@Socks Tried x<136 and x>630, it actually works! Now my actor can move from point to point with 0.1 second but i have another problem. I realized that when i press and hold my mouse button down on the preview screen, my actor would jump back and forth continuously. How do i make it in such a way whereby one press = one jump? So that the player has to release his finger and press again for another jump.
What does 'one jump' mean ? Left to Right and then back to Left - is that 'one jump' ?
I'd do it like this:
(the attribute 'A' is a 'real' attribute)
@Socks One jump means from left to right or from right to left. Anyway just to clarify, im using "touch is outside" but using my mouse to work on the computer.
@Socks This is the current state of my project and goal i want to achieve. please take a look.
Here you go, try this:
When you say you want the actor to 'immediately' jump from one side to another, do you want it to be instant (as in 0 seconds) or do you just want it to be very fast ?
@Socks Not 0 seconds, but very fast like 0.1 second. Yup i tried your solution above and when i held my mouse button down (which is touch, in this case) the actor keeps bouncing from left to right
@Socks Opps sorry i meant the solution before the latest solution. Will try your latest solution now!
Can you upload a screenshot of your version of this code.
@Socks Here you go,
@Socks And as for your latest solution
when i spammed click (spam touch) on my mouse, the actor will just move back and forth in the middle without running to completion
In this example you are using 'when touched is pressed' rather than 'when mouse button is down'.
Yep, that's how it's set up, you'd not mentioned previously that players should be prevented from rapidly clicking to change direction - the problem with a question slowly evolving like this is that you might answer the very same question from another user, and offer the same solution, but you design it so that the player cannot rapidly click to change direction . . . and you may well get the response _"when i spammed clicked I was unable to get the actor to change direction, it just carried on to the end of its run regardless of how many times I furiously pressed the screen"
That's why it's always best to lay out what you need in as much detail as is possible at the start of the process, rather than adding various caveats as you go along.
Try this . . .
(P.S. ignore my Ease in/ out settings on the Interpolate behaviour, you can set this to whatever you like).
@Socks I'm so sorry i didn't think that would happened initially. But yeah it happened. Anyway, right now its working the way i want it to, thanks to you! THANK YOU!!
@Socks Oh no wait, when i held the mouse button down all the way, it still bounces from left to right...
@Socks I want the player to lift up his finger and press again for the actor to move left/right, not hold his finger there and let the actor move rapidly
Why not upload a screenshot of your code ? Or should I ask each time !? People are unable to see what is in your project unless you share the code.
@Socks Here ya go!
...
@Socks ??
@Socks I don't get you. You provided me with a solution, i implemented it and found out that it isn't the way i want it to be and told you that it isn't working the way i want it to be. And then you asked for my code which makes me puzzled because it would obviously be your own code isn't it so why are you even asking? LOL. Nevertheless i still gave you the code and to my dismay, you replied me with dots.