improve on this ? (swipe to move actor)

goonergooner Lancaster, PAMember Posts: 135

i want my actor to mimic movement and interpolate location in any direction the player swipes on screen. it seems to work for the most part but there are some jittery movements as well as skipping directly to a position if release and retouch screen elsewhere.

1) when game area touch is pressed i set boolean attribute 'isMoving' to true and constrain two real attributes, 'currentX' to mouse.position.X and 'currentY' to mouse.position.Y

2) when 'isMoving' is true, I calculate differences for X and Y coordinates of actor to be moved vs the X and Y of where on screen the player touched into attribues 'diffX' and 'diffY'. This is so that the player can move around anywhere on screen and the actor will mimic the movement.

3) In actor to be moved, I constrain localX and localY attributes to 'currentX'-'diffX' and 'currentY'-'diffY'

4) If localX or localY does not equal corresponding self.Position.X or Y then interpolate self.Position.X or Y to corresponding localX or localY.

Also, when game area touch is released, then 'isMoving' is set to false.

if anyone has some experience with this please review and see if it looks ok, or if you have any recommendations for improvements I am always welcoming of advice ... thanks!

Comments

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

    I'd do it like this:

    When mouse button is down
    --Change A to mouse.X
    --Change B to mouse.Y
    --Timer / After 0.017 seconds
    ----Change velocity / Direction vectorToAngle(mouse.X-A,mouse.Y-B)

  • goonergooner Lancaster, PAMember Posts: 135

    @Socks said:
    I'd do it like this:

    When mouse button is down
    --Change A to mouse.X
    --Change B to mouse.Y
    --Timer / After 0.017 seconds
    ----Change velocity / Direction vectorToAngle(mouse.X-A,mouse.Y-B)

    appreciate this much more graceful solution ...

    unfortunately, i am not doing this right, actor exits the scene right no matter what i click, mouse down, mouse up, just keeps going off the right side.

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

    @ellison said:

    @Socks said:
    I'd do it like this:

    When mouse button is down
    --Change A to mouse.X
    --Change B to mouse.Y
    --Timer / After 0.017 seconds
    ----Change velocity / Direction vectorToAngle(mouse.X-A,mouse.Y-B)

    appreciate this much more graceful solution ...

    unfortunately, i am not doing this right, actor exits the scene right no matter what i click, mouse down, mouse up, just keeps going off the right side.

    Can you share a screenshot of your rule.

  • goonergooner Lancaster, PAMember Posts: 135

    @Socks said:

    Can you share a screenshot of your rule.

    Here's what I have ... thanks!

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

    @ellison said:

    @Socks said:

    Can you share a screenshot of your rule.

    Here's what I have ... thanks!

    You are using 'Constrain Attribute'.

  • goonergooner Lancaster, PAMember Posts: 135

    @Socks said:
    You are using 'Constrain Attribute'.

    Yeah, sloppiness on my part. When I didn't get it to work the first time I tried Constrain and got the same result (actor exits scene to the right)

    Here is current screen shot with same problem, thanks!

    Also, to clarify, these behaviors are in the actor/main character that I want to move around.

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

    @ellison said:
    Also, to clarify, these behaviors are in the actor/main character that I want to move around.

    Are there any other rules for this actor that would influence how it moves ?

  • goonergooner Lancaster, PAMember Posts: 135

    @Socks said:

    @ellison said:
    Also, to clarify, these behaviors are in the actor/main character that I want to move around.

    Are there any other rules for this actor that would influence how it moves ?

    hey @Socks, thanks for your patience ...

    there is nothing else inside that actor ...

    I did notice with further testing that it actually works for the most part, just two things I need to "fix"

    1) when you click mouse without swiping (just one quick click), do this anywhere on the scene and the actor exits to the right. I was "testing" this way to see if the actor would head in that direction and because of this I thought it wasn't working at all, my apologies.

    However, when I swipe/drag with mouse down it works as expected. Not sure why it doesn't travel toward the place you clicked or tapped, when it's just a mouse click.

    2) next problem, when moving properly, the actor still exits the scene because I do not have anything to slow down the velocity when mouse is not down. I want to this to have kind of an ice effect. I tried to interpolate both linear velocities (x, y) and max speed down to 0 but neither worked, one didn't stop, and one didn't move any longer after stopping. I'm going to try some high friction settings and see how that goes.

    Thanks!

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2016

    @ellison said:
    1) when you click mouse without swiping (just one quick click), do this anywhere on the scene and the actor exits to the right.

    A non-swiped click will mean the calculation V2A(mouse.X-A,mouse.Y-B) produces '0' as a result, 0° is angled to the right, so a single (unswiped) click will send an actor right. You just need to put in a condition that checks whether there has been any change in touch position before calculating the angle, you can use magnitude for this (try a low value like 5 or 10) . . .

    When mouse button is down
    --Change A to mouse.X
    --Change B to mouse.Y
    --Timer / After 0.017 seconds
    ----When magnitude(mouse.X-A,mouse.Y-B) is more than [insert a suitable value]
    ------Change velocity / Direction vectorToAngle(mouse.X-A,mouse.Y-B)

    @ellison said:
    2) next problem, when moving properly, the actor still exits the scene because I do not have anything to slow down the velocity when mouse is not down. I want to this to have kind of an ice effect. I tried to interpolate both linear velocities (x, y) and max speed down to 0 but neither worked, one didn't stop, and one didn't move any longer after stopping. I'm going to try some high friction settings and see how that goes.

    Your language is too vague for me to offer any help (I'm easy confused) - "one didn't move any longer after stopping" is especially troubling to me, lol :) . . . would you prefer the actor to continue to move after stopping ? Get that working and there's a Nobel prize in theoretical physics waiting for you :tongue:

    Friction effects the amount of speed carried over after a collision between two actors - Friction has no effect if an actor is not colliding with another actor.

    Try playing around with 'drag', drag will slow an actor (when using the physics engine).

    You could use the Otherwise section of the above code to introduce some drag once the mouse button is no longer pressed (see code below) - although your post leaves me a little confused as to whether or not you want your actors to stop or continue moving (but at a lower speed).

    When mouse button is down
    --Change A to mouse.X
    --Change B to mouse.Y
    --Timer / After 0.017 seconds
    ----When magnitude(mouse.X-A,mouse.Y-B) is more than [insert a suitable value]
    ------Change velocity / Direction vectorToAngle(mouse.X-A,mouse.Y-B)
    Otherwise
    --Change Drag to 200 [or whatever suitable value you prefer]

  • goonergooner Lancaster, PAMember Posts: 135

    thanks @Socks

    • Yup, Drag was what I needed. :)
    • Magnitude rule worked perfectly as well.
    • "one didn't move any longer after stopping", yeah should've said "actor didn't move again after the initial stop when making another swipe" B)

    1) question - should this rule have the actor mimic the whole swipe motion or just the initial direction, meaning if I swipe left then right, should the actor change directions left then right? or will it go left and only go right if I click the mouse again while swiping right?

    2) just a comment - most of the time with drag stopping the actor, the actor never gets exactly to linear velocities 0, it looks stopped, maybe twitches a little and when displaying text of the velocities they look trapped in a loop and keep changing values (for ex. i can make out 1 or -4, etc), not sure if that's a bug or not.

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

    @ellison said:
    1) question - should this rule have the actor mimic the whole swipe motion or just the initial direction, meaning if I swipe left then right, should the actor change directions left then right?

    I don't know what you mean by 'should' ? What happened when you tried it ? What would you prefer happened (ideally) ?

    @ellison said:
    2) just a comment - most of the time with drag stopping the actor, the actor never gets exactly to linear velocities 0 . . .

    When Velocity is < than [insert a suitable value] change velocity to 0.

  • goonergooner Lancaster, PAMember Posts: 135

    @Socks said:
    I don't know what you mean by 'should' ? What happened when you tried it ? What would you prefer happened (ideally) ?

    When Velocity is < than [insert a suitable value] change velocity to 0.

    1) Right now it only moves the actor in one direction. So if I swipe left right (mouse click down, then left, then right), the actor only moves left. If I click down, then move left, then click again and move right, the actor will move both left and right, when I click at the start of the new direction.

    Ideally, I would like the actor to follow the cursor as long as the player is still swiping/mouse down, without having to click again.

    2) I tried abs(linear.velocity.x and y) < 10 (change linear.velocity.x and y) = 0, and this seems to work nicely.

    thanks @Socks

Sign In or Register to comment.