Drag actor between 2 desired points on the x axis

Creator97Creator97 Member Posts: 140
edited December 2015 in Working with GS (Mac)

I want to integrate a tilt control with the accelerometer but I want the user also to be able to chose an alternative touch based control.
For that I thought it would be good to be able to drag an actor between 2 desired points on the x axis. If someone has a better idea please tell me.
So I set up in the actor I want to drag:
-If touch is pressed
change self.Position.X to game.Touches.Touch 1.X (BTW what is the point of selecting another touch or to choose one from the Active list?)

-Collide with Actor Wall (that are my 2 points on the X axis between I am dragging the actor)

That doesn't work because it will still drag my actor through the 2 walls.

So I set up
to do that: change self.Position.X to game.Touches.Touch 1.X
just when my actor is not overlapping with my Wall.

The problem with this is that it stops when it collides and then I cannot drag anymore.

I tried the same with 2 desired points on the x axis and just said additionally to the if touch is pressed that it would just be able to drag if the x position of my draggable actor is greater or lesser than the x value of my two points.

Same thing happens here it stopps moving when it has reached one of the 2 desired points.

Best Answers

  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,922
    edited December 2015 Accepted Answer

    There is a video over at gshelper youtube called constrain an actor and keep collisions intact. As I take it you want a control that slides between two places on the screen? If you use that method you can use your walls on the sides as the stopper and it will not lockout on you.

  • SocksSocks London, UK.Posts: 12,822
    Accepted Answer

    @Creator97 said:

    @AlchimiaStudios said:
    Yeah so do you want:

    • Actor can be moved anywhere on x axis within a range and stopped at any point along that range of min/max x positions.

    That's it right there. [loads of extra words . . . :) ]

    Constrain actor's X to min(max( game.Mouse.Position.X ,200),400)

    (change 200 and 400 to whatever you need)

  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,922
    Accepted Answer

    @Creator97 said:

    @Socks said:

    @Creator97 said:
    That's what I want to do and the way I thought it would work is **** because the actor I drag around does stop at different locations not every time the same as I would need it.
    BTW how would you integrate an alternative touch based control option to a accelerometer tilt control.
    So I think there's is an easier solution to the solution mentioned by oasis.

    I'm a little confused as to exactly what you are after ? There seem to be a few different questions tangled together and various examples of code and links and solutions that don't work.

    Even that I make it complicate you come still back to say that you don't understand instead of doing nothing I appreciate that.

    People here are only trying to help you. He couldn't offer you a opinion as he wasn't clear on what you wanted. As to the touch 1x you don't need to use that unless you are doing multitouch. The mouse position is the main touch. On a touch device your finger is the mouse.

Answers

  • Creator97Creator97 Member Posts: 140
    edited December 2015

    I kinda got it working now with a platform beneath the actor I want to drag. So just when mouse position is inside this platform I am able to drag my actor above it.

    If someone has a better solution please tell me.

    Edit: It doesn't work as wanted!

  • Creator97Creator97 Member Posts: 140
    edited December 2015

    Here is the direct link (project demo) of what you told me however there has to be a better and easier solution.
    http://gshelper.com/shop/free-templates-and-tutorials/constrain-to-mouse-and-keep-collision-gamesalad/

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

    @Creator97 said:
    I want to integrate a tilt control with the accelerometer
    I want the user also to be able to chose an alternative touch based control.
    For that I thought it would be good to be able to drag an actor between 2 desired points on the x axis. If someone has a better idea please tell me.
    So I set up in the actor I want to drag:
    -If touch is pressed
    change self.Position.X to game.Touches.Touch 1.X (BTW what is the point of selecting another touch or to choose one from the Active list?)

    -Collide with Actor Wall (that are my 2 points on the X axis between I am dragging the actor)

    That doesn't work because it will still drag my actor through the 2 walls.

    So I set up
    to do that: change self.Position.X to game.Touches.Touch 1.X
    just when my actor is not overlapping with my Wall.

    The problem with this is that it stops when it collides and then I cannot drag anymore.

    I tried the same with 2 desired points on the x axis and just said additionally to the if touch is pressed that it would just be able to drag if the x position of my draggable actor is greater or lesser than the x value of my two points.

    Same thing happens here it stopps moving when it has reached one of the 2 desired points.

    It's not entirely clear what you are asking (at least it's not clear to me) ?

    Do you simply want to drag an actor along the X axis but set limits for it at each end ? Or do you want it to jump between two different positions ?

  • Creator97Creator97 Member Posts: 140
    edited December 2015

    Do you simply want to drag an actor along the X axis but set limits for it at each end ?

    That's what I want to do and the way I thought it would work is !@#$% because the actor I drag around does stop at different locations not every time the same as I would need it.
    BTW how would you integrate an alternative touch based control option to a accelerometer tilt control.
    So I think there's is an easier solution to the solution mentioned by oasis.

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

    @Creator97 said:
    That's what I want to do and the way I thought it would work is **** because the actor I drag around does stop at different locations not every time the same as I would need it.
    BTW how would you integrate an alternative touch based control option to a accelerometer tilt control.
    So I think there's is an easier solution to the solution mentioned by oasis.

    I'm a little confused as to exactly what you are after ? There seem to be a few different questions tangled together and various examples of code and links and solutions that don't work.

  • AlchimiaStudiosAlchimiaStudios Member Posts: 1,069

    Yeah so do you want:

    • Actor can be moved anywhere on x axis within a range and stopped at any point along that range of min/max x positions.

    • Actor can be moved to points (A,B) on the x axis and it snaps to the closest point it's dragged when released

    • Actor can be moved to points (A,B) on the x axis and it snaps to the closest point it's dragged when released but cannot go beyond or below set X values.

    Follow us: Twitter - Website

  • Creator97Creator97 Member Posts: 140

    @Socks said:

    @Creator97 said:
    That's what I want to do and the way I thought it would work is **** because the actor I drag around does stop at different locations not every time the same as I would need it.
    BTW how would you integrate an alternative touch based control option to a accelerometer tilt control.
    So I think there's is an easier solution to the solution mentioned by oasis.

    I'm a little confused as to exactly what you are after ? There seem to be a few different questions tangled together and various examples of code and links and solutions that don't work.

    Even that I make it complicate you come still back to say that you don't understand instead of doing nothing I appreciate that.

  • Creator97Creator97 Member Posts: 140
    edited December 2015

    @AlchimiaStudios said:
    Yeah so do you want:

    • Actor can be moved anywhere on x axis within a range and stopped at any point along that range of min/max x positions.

    That's it right there. How I said the solution posted by oasis (I posted the link to) with two invisible objects would work but that's so much code for a really small thing. That's why am asking again because I know there's something easier.
    What would be great too if I would get your opinion on it if this additional touch control to my tilt accelerometer control for accelerating an actor to the left and to the right is a good way to do it.
    Example:
    -the actor I drag is in the middle of the desired x axis range: no acceleration to the actor I want to accelerate at all
    -the further I drag the actor to the right of the x axis range the faster the actor I want to accelerate accelerates to the right.
    -same for left

    I don't know what steps I need to take after I got that first thing even working that's why I ask for advice from you having a lot more experience as I have if my idea is even worth working on.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    He does this all the time. Gives half ass explanations and then when you ask him to clarify he gets testy. The method I suggested would have worked without a ton of code. I suggested constraining the Y position and then constraining the actor to the mouse velocity, which keeps normal collisions intact and will allow him to use to actors as stops.

    This would only need one rule and two constrains and one collide behavior. What the hell do I know, I've only been teaching GS for 4+ years.

  • Creator97Creator97 Member Posts: 140
    edited December 2015

    @Lost_Oasis_Games said:
    He does this all the time. Gives half ass explanations and then when you ask him to clarify he gets testy. The method I suggested would have worked without a ton of code. I suggested constraining the Y position and then constraining the actor to the mouse velocity, which keeps normal collisions intact and will allow him to use to actors as stops.

    This would only need one rule and two constrains and one collide behavior. What the hell do I know, I've only been teaching GS for 4+ years.

    I am sorry. I didn't get testy but I do understand what you are saying here. The next question I will ask I will be concrete at my very first post and I will ask just 1 question.
    And englisch isn't my main language that's why it's sometimes hard for me to bring something on the point. (Can you even say it like this? Does that make sense in english to to bring something on the point. Well, I don't know I am just translating what makes sense in german to english.)
    I don't know if I sound testy because I'm simply not as much connected to the english language as you are. That's all.
    That should be no excuse. I will just have to learn it.

Sign In or Register to comment.