Detect side click of actor

Hi, how can i detect witch side of the actor i press? I want that the more to left i click, the bigger motion.linear.velocity.x it gets.
So if i press all on the left on the actor it moves example motion.linear.velocity.x = 100, and if i press in the middle of the actor, it moved motion.linear.velocity.x = 0. Something like that.. Any suggestions?

Comments

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

    @ErikAuranaune said: if i press all on the left on the actor it moves example motion.linear.velocity.x = 100, and if i press in the middle of the actor, it moved motion.linear.velocity.x = 0

    (With a 100 x 100 pixel actor)

    When touch is pressed Change Velocity:
    Direction: 0
    Speed: max(0,min(100,(100-( game.Mouse.Position.X - self.Position.X )*2)-100))

  • ErikAuranauneErikAuranaune Member Posts: 35
    edited May 2015

    @Socks said:

    I tried this, but it only makes it move right. How do i do this also with right side?

  • SummationSummation Member, PRO Posts: 476

    @ErikAuranaune said:
    I tried this, but it only makes it move right. How do i do this also with right side?

    Try reversing it?

  • ErikAuranauneErikAuranaune Member Posts: 35

    @Summation said:
    Try reversing it?

    How exactly? It doesn´t work for me.

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

    @ErikAuranaune said:
    I tried this, but it only makes it move right. How do i do this also with right side?

    Lol :) I worked the expression out to precisely match your stated aims.

    "if i press all on the left on the actor it moves example motion.linear.velocity.x = 100, and if i press in the middle of the actor, it moved motion.linear.velocity.x = 0."

    It was actually quite tricky trying to get the maths to ignore the righthand side of the actor and only respond to the left - I wish people wouldn't approach questions in a piecemeal fashion ! The reason it only moves right is because that's what you asked for.

    I could give you the answer, but I suspect at that stage you will tell me that your actor is not 100 x 100 pixels, I would then change the expression to work with the size of your actor, at which stage you will tell me that the actor needs to rotate . . . (etc etc) :smiley:

    Play around with this . .

    When touch is pressed and mouse position is inside
    Change velocity to:
    Direction 0
    Speed ((100-( game.Mouse.Position.X - self.Position.X ))-100)*2

  • ErikAuranauneErikAuranaune Member Posts: 35

    @Socks said:

    Actually, my actor is 100 x 100 pixels :)

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

    @ErikAuranaune said:
    Actually, my actor is 100 x 100 pixels :)

    Then speed = ((100-( game.Mouse.Position.X - self.Position.X ))-100)*2 should work !! :smile:

  • ErikAuranauneErikAuranaune Member Posts: 35

    @Socks said:
    Then speed = ((100-( game.Mouse.Position.X - self.Position.X ))-100)*2 should work !! :smile:

    Yes, i used:
    Speed = ((100-( game.Mouse.Position.X - self.Position.X ))-100)*10

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

    @ErikAuranaune said:
    Speed = ((100-( game.Mouse.Position.X - self.Position.X ))-100)*10

    Thanks for all the feedback, you've been a pleasure to work for :smile: Lol.

  • ErikAuranauneErikAuranaune Member Posts: 35

    @Socks said:
    Thanks for all the feedback, you've been a pleasure to work for :smile: Lol.

    Haha, thanks for the good help mate! :)

Sign In or Register to comment.