Hello everyone,
I wanted to program a unique kind of movement for a part in my game where the player is on a raft.
My plan was to make a region that when clicked on, sets the player to walk to the mouse location, but with some distance added to simulate momentum.
Also it would be blocked so the player could only move to one location, then wait, and then move to another location to simulate the raft only moving when they paddle with an oar
function hswimtest_AnyClick()
{
//if the mouse is in front of the player
if (mouse.x > player.x){
player.Move(mouse.x+5, mouse.y, eNoBlock, eAnywhere);
//if the mouse is behind the player
}else if (mouse.x < player.x){
player.Move(mouse.x-5, mouse.y, eBlock, eAnywhere);
}
}
The issue is the mouse coordinates seem to change to the far left of the screen, and the character moves there instead of where the mouse had clicked.
As far as I can tell the in-engine walk mechanics aren't interfering with this. Thoughts?
is this a scrolling room? Then you have to add the viewport coordinates to the mouse coordinates.
Quoteis this a scrolling room? Then you have to add the viewport coordinates to the mouse coordinates.
This IS a scrolling room!
How would I go about adding the viewport coordinates to the mouse coordinates?
This is asked every now and then in the tech forums -
http://www.adventuregamestudio.co.uk/forums/index.php?topic=51063.msg636497399#msg636497399
function hswimtest_AnyClick()
{
//if the mouse is in front of the player
if (mouse.x > player.x){
player.Move(GetViewPortX() + mouse.x+5, GetViewPortY() + mouse.y, eNoBlock, eAnywhere);
//if the mouse is behind the player
}else if (mouse.x < player.x){
player.Move(GetViewPortX() + mouse.x-5, GetViewPortY() + mouse.y, eBlock, eAnywhere);
}
}
dayowlron, you forgot to subtract Viewport coordinate from player.x:
if (mouse.x > player.x - GetViewportX())
IMO its better to translate everything into room coordinates first. This way the further calculations will be much simplier.
int room_click_x = mouse.x + GetViewportX();
int room_click_y = mouse.y + GetViewportY();
if (room_click_x > player.x){
player.Move(room_click_x + 5, room_click_y, eNoBlock, eAnywhere);
and so on...
EDIT: my apologies, did wrong conversion :) fixed now.
good point.