Troubleshooting - Make Actor move to Mouse click

I'll start with what I want to do, and then I'll detail what I've already done (and what seems to be happening).
I have a scene that is bigger than the camera. I want to be able to click mouse/touch (without having to hold) and have my actor move to that position (while moving the camera origin). I'm doing this for an rpg type game, so the scene will be huge. I also don't want a Dpad on an iphone, so I'm experimenting with this type of movement.
What I've done so far....
I've set up the camera offset so that I can track camera origin.
I've set up attributes that track each time the mouse is clicked.
I've experimented with mouse down/up, touch press/release, a boolean "movetrue", and a direct move to touch x/y.
I've experimented with move to and interpolate (I love interpolate, but I want my hero to move at the same speed regardless of distance)
This is what is happening...
When I click inside of the original camera zone, it works fine. When I click outside of the original camera zone, the hero moves towards that point (with camera following) but will usually continue past the point I clicked (even though its basing its movement off the registered click attributes). I'll try to describe what appears to be happening. Once I click off the original camera zone, it seems to confuse the coordinates of the click with the click in relation to screen. I set up a display text to confirm this. My scene size is 960wide. When I click on the far right of the screen, it registers my click as ~x470, but the actor moves to ~x950.
I want to be able to click on coord. x 450, and have my actor move there. When coord. x 750 is visible, I want to be able to click it, and have my actor move there.
It was kind of hard for me to articulate this problem, so hopefully its clear. Any help is much appreciated!
I have a scene that is bigger than the camera. I want to be able to click mouse/touch (without having to hold) and have my actor move to that position (while moving the camera origin). I'm doing this for an rpg type game, so the scene will be huge. I also don't want a Dpad on an iphone, so I'm experimenting with this type of movement.
What I've done so far....
I've set up the camera offset so that I can track camera origin.
I've set up attributes that track each time the mouse is clicked.
I've experimented with mouse down/up, touch press/release, a boolean "movetrue", and a direct move to touch x/y.
I've experimented with move to and interpolate (I love interpolate, but I want my hero to move at the same speed regardless of distance)
This is what is happening...
When I click inside of the original camera zone, it works fine. When I click outside of the original camera zone, the hero moves towards that point (with camera following) but will usually continue past the point I clicked (even though its basing its movement off the registered click attributes). I'll try to describe what appears to be happening. Once I click off the original camera zone, it seems to confuse the coordinates of the click with the click in relation to screen. I set up a display text to confirm this. My scene size is 960wide. When I click on the far right of the screen, it registers my click as ~x470, but the actor moves to ~x950.
I want to be able to click on coord. x 450, and have my actor move there. When coord. x 750 is visible, I want to be able to click it, and have my actor move there.
It was kind of hard for me to articulate this problem, so hopefully its clear. Any help is much appreciated!
Comments
Try to edit your actor (you want to move) in your scene (not your prototype actor)...
In the move to, write that :
Move to : game.Mouse.Position.X + scene.Camera.Origin.X (current scene camera origin)
Same for Y :
Move to : game.Mouse.Position.Y + scene.Camera.Origin.Y
Let me know... Cheers
Change attribute "self.position" to "self.positionX+450(tracked)" & the same for Y
This, will change the position, but to make the actor move to that position, you could make two new actor attributes 'destinationX' and 'destinationY' that are the mouse tracked position+self.posX&Y and make the actor Move to self.destinationX and self.destinationY when you touch.
I don't know if this would work
Hope it helps
Unfortunately, this lead to the same result. Thanks anyways.
@latygo60
I wasn't able to make this work. Thanks anyways.
In playing around with this, I am unable to get GS to understand any coordinates outside of the 480X320 box. My scene is double these dimensions, so I thought I'd be able to log coordinates like 500,500, or 720, 480 etc. Does this mean GS doesn't understand a large area, or am I doing something wrong?
Really? I'll take a closer look then.
That method made my hero constrain itself to the mouse cursor. I don't want my hero to move continously. I want the hero to move to the mouse click position, and stay there unless another mouse click is register. I then tried doing the same approach with mouse.touch instead, and it replicated my original issue.
Have an icon to click on (move character)... that's for the game to know that you want to move your character.
RULE : When "move icon"=1
-Rule : When mouse button is down
--Move to : magnitude( game.Mouse.Position.X , self.Position.X )+ scene.Camera.Origin.X
magnitude( game.Mouse.Position.Y , self.Position.Y )+ scene.Camera.Origin.Y
Perhaps I can be of assistance. I made a gamesalad template that explains how to do what you are looking for.
I set it up so that the actor only moves when the mouse button is down, and moves to the mouse x and y coordinates. And when the mouse button is up, the x and y of the actor are constrained.
Hope this helps
-Matt
The problem lies with GS only recognizing coordinates within the 480 X 320 original camera view. The camera offset works perfectly if you constrain the hero to the mouse, or you hold down the button. But as soon as you try to make it a press/release, it confuses the coordinates, and the hero that is supposed to go to 480, 320 actually goes to 960, 640.
Stormy Studios has this in his top down shooter template. I've shot an email to him to see if I can dredge up any info on it.
Zip it and Email it to sebby_zzzz (at) hotmail (dot) fr
Cheers