GameSalad

Howdy, Stranger!

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

Touch controls without any buttons involved?

ohtukrwohtukrw Sir dogePosts: 106Member
edited July 2016 in Help Wanted

How do I make the actor accelerate where the touch is based on the x axis?

Comments

  • tatiangtatiang Posts: 11,786Member, Sous Chef, PRO, Senior Sous-Chef

    It's not really clear what you're asking. Is the acceleration to be controlled by how long someone taps/clicks within a certain area or by how low/high the touch X position is?

    For the latter, you would use the mouse position (game.mouse.position.X and game.mouse.position.Y).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • NNterprisesNNterprises Posts: 387Member, PRO
    edited July 2016

    Two generic guidelines:
    1. "Help Wanted" is for people who want to post to pay people for game development, art, or post their availability to work; you may want to change the topics you keep posting under as "Working With GS"
    2. If you Google search your question with "Gamesalad" before it, it is a lot easier to find answers on these forums than the forum search above. It may help you out more

    Back to Question answering:
    Not sure what "touch is based on the x axis means". Do you want to "swipe" on the x axis? or just touch somewhere on a specific horizontal line?

  • ohtukrwohtukrw Sir doge Posts: 106Member
    edited July 2016

    Touch once without the longevity of the touch involved. > @tatiang said:

    It's not really clear what you're asking. Is the acceleration to be controlled by how long someone taps/clicks within a certain area or by how low/high the touch X position is?

    For the latter, you would use the mouse position (game.mouse.position.X and game.mouse.position.Y).

    I want the hero to accelerate left or right (x axis) where the touch is pressed once (without touch longevity involved)

    What would be the full rule please? As English is not my native I struggle with the different function meanings. :smile:

  • IceboxIcebox Posts: 1,483Member

    @ohtukrw said:
    I want the hero to accelerate left or right (x axis) when the touch is pressed once (without touch longevity involved)

    What would be the full rule please? As English is not my native I struggle with the different function meanings. :smile:

    Create a boolean call it accelerate

    if touch is pressed
    change attribute accelerate to true

    if attribute self.accelerate is true
    accelerate right or left

    This way it wont depend on touch longevity , but it will accelerate so the speed will increment , you can have a max speed if you want , or use change attribute self.motion linear velocity x.

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

    @ohtukrw said:
    I want the hero to accelerate left or right (x axis) when the touch is pressed . . .

    This is still a little confusing . . . is the direction (left or right) chosen randomly when you touch the actor ?

  • ohtukrwohtukrw Sir doge Posts: 106Member
    edited July 2016

    @Socks said:

    @ohtukrw said:
    I want the hero to accelerate left or right (x axis) when the touch is pressed . . .

    This is still a little confusing . . . is the direction (left or right) chosen randomly when you touch the actor ?

    Sorry, my bad wording.
    When players touched outside the actor (main hero) anywhere on the screen, to determine where the actor should accelerate to, affecting only x linear movement.

  • ohtukrwohtukrw Sir doge Posts: 106Member
    edited July 2016

    hmm

  • IceboxIcebox Posts: 1,483Member

    @ohtukrw said:
    how can I apply the max speed? :)

    Here just give it a number and tick apply max speed

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

    @ohtukrw said:
    When players touched outside the actor (main hero) anywhere on the screen, to determine where the actor should accelerate to, affecting only x linear movement.

    @tatiang said:
    . . . you would use the mouse position (game.mouse.position.X . . . .

  • IceboxIcebox Posts: 1,483Member

    @ohtukrw If you want the touch to be anywhere on the screen do

    if mouse button is down instead of if touch is pressed

  • IceboxIcebox Posts: 1,483Member
    edited July 2016

    @ohtukrw said:
    When players touched outside the actor (main hero) anywhere on the screen, to determine where the actor should accelerate to, affecting only x linear movement.

    I attached a demo if you want , im sure there is an easier way to do it.

    Hope it helps

  • ohtukrwohtukrw Sir doge Posts: 106Member

    @Icebox said:

    @ohtukrw said:
    When players touched outside the actor (main hero) anywhere on the screen, to determine where the actor should accelerate to, affecting only x linear movement.

    I attached a demo if you want , im sure there is an easier way to do it.

    Hope it helps

    you are amazing

  • ohtukrwohtukrw Sir doge Posts: 106Member

    @Icebox said:

    @ohtukrw said:
    When players touched outside the actor (main hero) anywhere on the screen, to determine where the actor should accelerate to, affecting only x linear movement.

    I attached a demo if you want , im sure there is an easier way to do it.

    Hope it helps

    TL;DR Solution found

    Long:
    Well I have tried your complex rules and it didn't work.

    Because my game already has accelerate in direction 0. And your rule triggers either left or right acceleration on touch, it eliminates other movement rules, which is in my case.

    The way I set up my computer keyboard controls, which work is:

    self.motion.linearvelocity.x to - or + direction and is accordingly set up to execute once, when the necessary key is pressed, that way my accelerate in direction 0 rule isn't affected and the hero travels without pressing anything.

    People mentioned game.mouse.position.x, so it took me some frowning until this happened:

    when
    game.mouse.position.x<self.position.x
    mouse down
    do accelerate direction 180

    and vice versa, which are more simplistic.

    I will try to add self.motion.linearvelocity.x instead of accelerate like I did on the keyboard, hopefully it works.

    Grey matter gained +1 xD

  • ohtukrwohtukrw Sir doge Posts: 106Member
    edited July 2016

    @Socks said:

    @ohtukrw said:
    When players touched outside the actor (main hero) anywhere on the screen, to determine where the actor should accelerate to, affecting only x linear movement.

    @tatiang said:
    . . . you would use the mouse position (game.mouse.position.X . . . .

    Why is the hero jerking back and forth when touched at right side?

    http://www33.zippyshare.com/v/sgA1gPWv/file.html

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

    @Icebox said:
    I attached a demo if you want , im sure there is an easier way to do it.

    You can simplify this same idea, delete all the rules and replace them with . .

    When mouse button is down:
    --Accelerate / Direction V2A(mouse X - self X, 0)

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

    @ohtukrw said:
    Why is the hero jerking back and forth when touched at right side?

    http://www33.zippyshare.com/v/sgA1gPWv/file.html

    Unlock Actor 1 . . . delete your touch right and touch left rules . . . and replace them with this one rule:

    It's not clear why you have an Accelerate (right) behaviour and a Liner Velocity (right) too . . . ? If you switch off the Linear Velocity (right) behaviour it makes no difference to the project.

    X.png 1.2M
  • ohtukrwohtukrw Sir doge Posts: 106Member
    edited July 2016

    @Socks said:

    @ohtukrw said:
    Why is the hero jerking back and forth when touched at right side?

    http://www33.zippyshare.com/v/sgA1gPWv/file.html

    Unlock Actor 1 . . . delete your touch right and touch left rules . . . and replace them with this one rule:

    It's not clear why you have an Accelerate (right) behaviour and a Liner Velocity (right) too . . . ? If you switch off the Linear Velocity (right) behaviour it makes no difference to the project.

    My project is a hero jumping and is moving relative to the scene. I want it to move forward all the time, so it has to be affected by some force, which is accelerate to 0 direction. Linear velocity is for controls when it is falling down, or jumping up in the air to avoid obstacles. Any other movement type would mess up the feel of the fall. Imagine a bouncing ball which moves forward all the time. The movement idea is working perfectly with computer keyboard keys, however it keeps jerking when implemented into touch :(

  • IceboxIcebox Posts: 1,483Member

    @Socks said:

    @Icebox said:
    I attached a demo if you want , im sure there is an easier way to do it.

    You can simplify this same idea, delete all the rules and replace them with . .

    When mouse button is down:
    --Accelerate / Direction V2A(mouse X - self X, 0)

    He wants it so that when you touch once it accelerates at full speed , your method can be done but you have to keep pressing , if you touch the screen once it accelerates slowly , so thats why the rule i put was complex and not simplified. If he was to use motion linear velocity it would have been easier. But i learned something new with this thanks , you always surprise me with your simplified behaviors :)

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

    @ohtukrw said:
    . . . it keeps jerking when implemented into touch

    Did you try my suggestion above ?

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

    @Icebox said:
    He wants it so that when you touch once it accelerates at full speed , your method can be done but you have to keep pressing . . .

    Ah! I didn't realise that's what was wanted.

    If you wanted it to keep accelerating when the mouse is released you could use this:

    When mouse button is down:
    --Change D to V2A(mouse X - self X, 0)

    Accelerate / Direction D

  • ohtukrwohtukrw Sir doge Posts: 106Member
    edited July 2016

    @Socks said:

    @ohtukrw said:
    . . . it keeps jerking when implemented into touch

    Did you try my suggestion above ?

    Problem fixed thank you.

  • ohtukrwohtukrw Sir doge Posts: 106Member
    edited July 2016

    @Socks said:

    @Icebox said:
    He wants it so that when you touch once it accelerates at full speed , your method can be done but you have to keep pressing . . .

    Ah! I didn't realise that's what was wanted.

    If you wanted it to keep accelerating when the mouse is released you could use this:

    When mouse button is down:
    --Change D to V2A(mouse X - self X, 0)

    Accelerate / Direction D

    Problem fixed. Thank you

  • ohtukrwohtukrw Sir doge Posts: 106Member

    Actually fixed the problem ,thank you everyone who posted. Fixed the jerking with the -scene.camera.origin.x socks have provided. Can lock this thread :)

    If someone is interested for a bouncing ball with touch controls, here is the final link:
    http://www23.zippyshare.com/v/i0h1YyME/file.html

Sign In or Register to comment.