Constraining an actor to touch, but with an offset...

iCreationZiCreationZ Member Posts: 158
edited July 2012 in Working with GS (Mac)
I'm working on a new game, but I'm stuck with what I thought what be a simple control.

How (if possible) can i constrain an actor to touch, but with the offset of where the touch is?

So if the actor is selected, and then the player touches and drags the other side of the screen, how can I have the actor move in proportion?

It's completely baffled me, so I'd be greatly appreciative of anyones help!

Thanks, Jamie

Comments

  • J_PANJ_PAN Member Posts: 140
    when mouse button is down and touch is pressed constrain attribute self.positionX to game.MousePositionX and constrain attribute self.positionY to game.MousePositionY. It should work, if it doesn't, leave a comment and I will try to correct it.

    Hope this works,

    pan_joshua
  • iCreationZiCreationZ Member Posts: 158
    I've got that rule working, but what I'm really after is a way to move the object without touching it...

    Trouble is, when the actor is pressed it makes it difficult to see it, so precise movements are nearly impossible.

    I need a way of moving the actor with touch, but without pressing it.

    Currently in this quest, I have a system of selecting an actor, but now i just need a way of moving it remotely... :-/

    Thanks for your help pan_joshua!

    Jamie
  • OskarDeveloperOskarDeveloper Member Posts: 533
    edited July 2012
    So you want to move it with buttosn or what do you mean? Aslo if you want the actor to be seen and not covered when he is pressed you can type minus and then a number (constarin self.postionX to game.mouseposition X-100) that will make the actor move 100 pixels to the left when he is pressed, but it will still follow the mouse :D
  • iCreationZiCreationZ Member Posts: 158
    That does sound like a fix, but what I'm really after is to be able to select an actor, then say if you slide the other side of the screen from 400 to 50, the actor would move down in the same proportio, but would not get any closer to the touch. And if the touch is pressed and dragged horizontally, the actor would move horizontally, but maintain its current distance from the touch... I think I'm making this sound much more complicated than it probably is...
  • KodeRiter722KodeRiter722 Member Posts: 42
    Just add or subtract the number of pixels you want for the offset in each direction from the point of touch (X and Y).

    When mouse button is down:

    - constrain attr: self.position.x to mouse.position.x (+ or -) [some # of pixels]
    - constrain attr: self.position.y to mouse.position.y (+ or -) [some # of pixels]

  • OskarDeveloperOskarDeveloper Member Posts: 533
    @Frostbyte Yeah i told you how to do that!
    @KodeRiter722 I have already said that :p
  • iCreationZiCreationZ Member Posts: 158
    @OskarDeveloper, Sorry, I think I may just be confusing myself over this issue!
    @KodeRiter722, Thanks for clarifying!

    Thanks!
    I'll keep you posted on how I get on!
  • OskarDeveloperOskarDeveloper Member Posts: 533
    Haha np @Frostbyte :)
    thanks
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited July 2012
    You might want something like this:

    Make two self attributes (of type real). Name them xOffset, and yOffset. Then add the following rule.

    When Mouse button is down
    --Change Attribute:self.xOffset To:self.Position.X - game.Mouse.Position.X
    --Change Attribute:self.yOffset To:self.Position.Y - game.Mouse.Position.Y
    --Constrain Attribute:self.Position.X To:game.Mouse.Position.X + self.xOffset
    --Constrain Attribute:self.Position.Y To:game.Mouse.Position.Y + self.yOffset
  • KodeRiter722KodeRiter722 Member Posts: 42
    @oskardeveloper I guess I should have read your entire comment :P mine is a little more generic at least...
  • iCreationZiCreationZ Member Posts: 158
    For some reason I'm still really struggling with this one... I can't seem to get the actor to move in proportion to the touch, but whilst still maintaining its distance from it... The aim is to let the player drag and drop the actor into place, and then to move it more precisely by dragging anywhere on the screen to finely adjust its position, because as the actor is fairly small, it makes it difficult to see and move it under my fairly chubby finger.

    I have tried all suggestions but so far, nothing seems to have been successful (But thanks for everyones contributions so far!).
  • 007leokart007leokart Member Posts: 38
    Put a constrain project in the actor you want to move the following:
    Self.Position.X to device.touches.touch 1.X
    Self.Position.Y to device.touches.touch 1.Y

    if you want to see the actor moving to the touch instead of constraining the actor make an interpolate.
  • iCreationZiCreationZ Member Posts: 158
    edited July 2012
    @007leokart I have that working at the moment, but i need a way to offset it to coordinate with the position of the touch... So if you swipe the screen down opposite the actor, the actor will also go down, just without moving to the touches position.
  • iCreationZiCreationZ Member Posts: 158
    If anyone else have had any luck with this issue, don't hesitate to share. It's still got me... ;)
  • iCreationZiCreationZ Member Posts: 158
    EXACTLY!!!! :D
  • iCreationZiCreationZ Member Posts: 158
    Now how's it done? Haha! :)
  • iCreationZiCreationZ Member Posts: 158
    something like this?
    So does anyone know how I can achieve something like this?

  • iCreationZiCreationZ Member Posts: 158
    @uptimistik Thank you so much! I really look forward to dissecting this tomorrow, and I'll endeavour to learn as much as I can from it! Thanks again!
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    You realize there is a video on this in the gamesalad cookbook YouTube page right?
  • iCreationZiCreationZ Member Posts: 158
    @uptimistik, That is such a simple way of doing it! Thank you so much, it's exactly what I was after!
    @tenrdrmer, I don't know how I've missed that, I've been searching for weeks!

    Thanks for everyones contribution!
Sign In or Register to comment.