Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Thu 05/09/2013 09:46:01

Title: SOLVED: Walk to mouse x y+340 co-ords
Post by: Slasher on Thu 05/09/2013 09:46:01
Hi

What I am trying to do is have the character cSpaceman walk to mouse x, mouse y+340

It is a 'scrolling' room and events are activated by a hotspot to throw a projectile straight up after cSpaceman has reached mouse x mouse y +340.
Code (ags) Select

cSpaceman.Walk(mouse.x+GetViewportX(), mouse.y+GetViewportY());

// Was using this but it ignores scrolling room.
cSpaceman.Walk(mouse.x, mouse.y+340, eBlock, eWalkableAreas);



Will you assist me please.

cheers

Title: Re: Walk to mouse x y+340 co-ords
Post by: Crimson Wizard on Thu 05/09/2013 09:50:36
Slasher, you are correctly using Viewport in the first line. You should use it in similar way in the second line:
Code (ags) Select

cSpaceman.Walk(mouse.x + GetViewportX(), mouse.y + GetViewportY()+ 340, eBlock, eWalkableAreas);


Viewport should be used all time in the scrolling room when you use coordinates relative to screen (e.g. mouse position).
Title: Re: Walk to mouse x y+340 co-ords
Post by: Gilbert on Thu 05/09/2013 09:55:13
I don't quite understand the situation. What is supposed to mean by mouse.x + 340?

The problem is, when you click on a spot, the screen could have been scrolled beforehand, so if you use the coordinates (mouse.x, mouse.y+340), if you say, click at (100, 100) of the screen, the character will always walk to room coordinates (100, 440), no matter where the current viewport is at. If you want the destination room coordinates to have the same x-coordinates as before, and add 340 to the current y-coordinates, just straight forward make him walk to (mouse.x+GetViewportX(), mouse.y+GetViewportY()+340), though if the character is already close to the bottom edge of the room, the destination could be off-screen. Is this what you want? Otherwise please clarify your problem.

Edit: Ninja'd by Crimson Wizard, but I'll post anyway.
Title: Re: Walk to mouse x y+340 co-ords
Post by: Slasher on Thu 05/09/2013 09:59:19
Thank you so much for your help Crimson

It seems to do the trick (nod)

cheers