GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Touch controls with angles

I'v almost finished my game and for the controls for the main character I've used tshirtbooths tutorial
this has worked really well but what i want to do is add angles to it, its clear that you can select an angle for it go on at the end of the code but to record it in the first place there's only X and Y.
I thought maybe tshirtbooths vid on recording angular velocity in the custom pause menu could be incorporated to record it but my head is exploding trying to bring these 2 things together.
Has anyone done this before swipe control for an actor from anywhere on the screen that includes angles?

Comments

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

    I'm not 100% quite what the question is (and I couldn't be bothered to watch a 10 minute video to find out ! :) ), but if you are basically after a rule that records the direction in which you swipe you can do it like this:

    Make 3 attributes (all real), A, B and C.

    When mouse button is down
    --Change A to mouseX
    --Change B to mouseY
    --Timer: After 0.1
    ----Change C to vectorToAngle(mouseX-A,mouseY-B)%360

    The angle of the swipe is now recorded into the attribute called 'C', and you can then use it as you need.

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

    Here are a couple of examples (demo file attached):

    Click anywhere on the screen and swipe to move the actor.

    Inside the actor there are three variations on the basic rule, switch each one on (and the others off!) to see how each works.

    1) Instant direction change swipe [fixed speed]
    2) Smooth direction change swipe [fixed speed]
    3) Smooth direction change swipe [speed based on speed of swipe]

  • Oh mate that's perfect! thankyou so much!
    I Was gonna start another conversation but since you're pretty clued up and i've got you here...
    I've just discovered that in order to have a universal build i should have started on an ipad with landscape, how ever i started on iphone 5 portrait, the game is only played in portrait so that's cool but is there anyway i can plug code in now to get it to fit other devices?
    I came across a video a little while ago on a guy who found a way to have his project adapt and resize to anything but i can find the video again...

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

    @grahameckersley said:
    I've just discovered that in order to have a universal build i should have started on an ipad with landscape . . .

    Only if you wanted a Landscape game, obviously if your game is Potrait it would be a bad starting point . . also you don't have to have started with an iPad project, this is just a recommendation, there are other viable ways of producing a universal game.

    I'd start a new thread, there are lots of clever universal build approaches out there and the people who know their way around this stuff might not click on a Touch Controls thread.

    @Armelline had a very good one recently . . .

  • Ok cool man thank you

  • So i set it up just the way you did in the demo but its not working, the only difference i can see is you explained to use attribute c to record the angle but there's nothing like that in the code on the demo i followed the code step by step and it was all X and Y,
    Am i overlooking something here...

  • Actually i just tried it again in a new project and it works perfectly i must have some conflicting code in there to hunt out

  • New question,
    The controls you gave me work brilliantly thankyou!
    On the first 2 when you make a single tap on the screen the ball will shoot off to the left and in the last one it comes to a stop, I've been trying to work out what that difference is as what I'm trying to do is have it so that in the first option it simply doesn't shoot of to the left with a single tap, is this possible or have i been chasing ghosts?

Sign In or Register to comment.