Move to.

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


«1

Comments

  • birdboybirdboy Member Posts: 284
  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2015

    Use the Interpolate behaviour instead.

    Or constrain the actor's X position to: 248 *sin (self.time *181.45) +383

  • benjaminmagebenjaminmage Member Posts: 74

    @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.

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2015

    @benjaminmage said:
    Socks I tried the interpolate behaviour, it works perfectly fine until i dropped the timing to 0.1 seconds using linear function.

    Did you want the actor to move across the screen in a tenth of a second !? :smile:

    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:

    And as for the Actor's X position, i dont quite get you.

    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 ! :smile:

    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.

  • SocksSocks London, UK.Member Posts: 12,822

    @Summation said:
    Socks is a superhero, I tell ya!

    At last, the sock / superhero crossover I have been waiting for ! :smile:

  • benjaminmagebenjaminmage Member Posts: 74

    @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!!

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2015

    @benjaminmage said:
    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.

    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)

    @benjaminmage said:
    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.

    Can you take a screenshot of the code for this ? Are you sure you have no other rules running, just a single constrain behaviour ?

  • benjaminmagebenjaminmage Member Posts: 74

    @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.

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2015

    @benjaminmage said:
    How do i make it in such a way whereby one press = one jump?

    What does 'one jump' mean ? Left to Right and then back to Left - is that 'one jump' ?

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2015

    I'd do it like this:
    (the attribute 'A' is a 'real' attribute)

  • benjaminmagebenjaminmage Member Posts: 74

    @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. :)

  • benjaminmagebenjaminmage Member Posts: 74

    @Socks This is the current state of my project and goal i want to achieve. please take a look.

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2015

    @benjaminmage said:
    Socks One jump means from left to right or from right to left.

    Here you go, try this:

  • SocksSocks London, UK.Member Posts: 12,822

    @benjaminmage said:
    Picture with weird fingers . . .

    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 ?

  • benjaminmagebenjaminmage Member Posts: 74

    @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

  • benjaminmagebenjaminmage Member Posts: 74

    @Socks Opps sorry i meant the solution before the latest solution. Will try your latest solution now!

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2015

    @benjaminmage said:
    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

    Can you upload a screenshot of your version of this code.

  • benjaminmagebenjaminmage Member Posts: 74

    @Socks Here you go,


  • benjaminmagebenjaminmage Member Posts: 74

    @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

  • SocksSocks London, UK.Member Posts: 12,822

    @benjaminmage said:
    Socks Here you go,

    In this example you are using 'when touched is pressed' rather than 'when mouse button is down'.

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2015

    @benjaminmage said:
    when i spammed click (spam touch) on my mouse, the actor will just move back and forth in the middle without running to completion

    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).

  • benjaminmagebenjaminmage Member Posts: 74

    @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!!

  • benjaminmagebenjaminmage Member Posts: 74

    @Socks Oh no wait, when i held the mouse button down all the way, it still bounces from left to right...

  • benjaminmagebenjaminmage Member Posts: 74

    @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

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2015

    @benjaminmage said:
    Socks Oh no wait, when i held the mouse button down all the way, it still bounces from left to right...

    Why not upload a screenshot of your code ? Or should I ask each time !? :smiley: People are unable to see what is in your project unless you share the code.

  • benjaminmagebenjaminmage Member Posts: 74

    @Socks Here ya go!



  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2015

    ...

  • benjaminmagebenjaminmage Member Posts: 74

    @Socks ??

  • benjaminmagebenjaminmage Member Posts: 74

    @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. :)

Sign In or Register to comment.