Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411512 Posts in 69376 Topics- by 58431 Members - Latest Member: Bohdan_Zoshchenko

April 27, 2024, 10:43:53 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)[SOLVED]Restrict movement to inside a view using driving controls
Pages: [1]
Print
Author Topic: [SOLVED]Restrict movement to inside a view using driving controls  (Read 1944 times)
imaginationac
Level 2
**


Makin' games instead of makin' money.


View Profile WWW
« on: January 02, 2010, 11:25:22 AM »

So for a prototype I'm working on for a overhead shooter, I have the player controled by driving; that is forward, reverse, and turning. That was simple enough to do. What I want to have happen is to make sure the player can never move off-screen, or at least for now, not off the view.

I've tried a few things out short of writing a complicated series of conditionals, but none of them seem to work.

Using GM 8 Pro BTW.

Any guidance of any sort would be great. This is the last technical hurdle I have to push through; all the other mechanics are in place! Crazy
« Last Edit: January 02, 2010, 01:30:42 PM by Dorian Patterson » Logged

Youtube channel | Charger! Dev Log
              
Theotherguy
Level 1
*



View Profile
« Reply #1 on: January 02, 2010, 12:22:15 PM »

So for a prototype I'm working on for a overhead shooter, I have the player controled by driving; that is forward, reverse, and turning. That was simple enough to do. What I want to have happen is to make sure the player can never move off-screen, or at least for now, not off the view.

I've tried a few things out short of writing a complicated series of conditionals, but none of them seem to work.

Using GM 8 Pro BTW.

Any guidance of any sort would be great. This is the last technical hurdle I have to push through; all the other mechanics are in place! Crazy

Does your view of the world move?
Logged

pgil
Guest
« Reply #2 on: January 02, 2010, 12:47:40 PM »

The simplest way would be to check the player's position in relation to the view's position:

Code:
if x < view_xview[0]                 x = view_xview[0]
if x > view_xview[0] + view_wview[0] x = view_xview[0] + view_wview[0]
if y < view_yview[0]                 x = view_yview[0]
if y > view_yview[0] + view_hview[0] x = view_yview[0] + view_hview[0]
Logged
imaginationac
Level 2
**


Makin' games instead of makin' money.


View Profile WWW
« Reply #3 on: January 02, 2010, 01:10:28 PM »

Does your view of the world move?

No. It's stationary.
The simplest way would be to check the player's position in relation to the view's position:

Code:
if x < view_xview[0]                 x = view_xview[0]
if x > view_xview[0] + view_wview[0] x = view_xview[0] + view_wview[0]
if y < view_yview[0]                 x = view_yview[0]
if y > view_yview[0] + view_hview[0] x = view_yview[0] + view_hview[0]

I'm not sure I get what you mean. Your code snippet seems to reposition the player's position at either the x coordinate of the view or the x coordinate plus the width of the view, which is not what I want to do.

Perhaps if I rephrase. I want the boundaries of the view to act as though they were solid. Is this possible without creating objects?
Logged

Youtube channel | Charger! Dev Log
              
Theotherguy
Level 1
*



View Profile
« Reply #4 on: January 02, 2010, 01:24:28 PM »

Does your view of the world move?

No. It's stationary.
The simplest way would be to check the player's position in relation to the view's position:

Code:
if x < view_xview[0]                 x = view_xview[0]
if x > view_xview[0] + view_wview[0] x = view_xview[0] + view_wview[0]
if y < view_yview[0]                 x = view_yview[0]
if y > view_yview[0] + view_hview[0] x = view_yview[0] + view_hview[0]

I'm not sure I get what you mean. Your code snippet seems to reposition the player's position at either the x coordinate of the view or the x coordinate plus the width of the view, which is not what I want to do.

Perhaps if I rephrase. I want the boundaries of the view to act as though they were solid. Is this possible without creating objects?

If your view is stationary then this code is right, sort of. It should be this:
Code:
if x < view_xview[0]                 x = view_xview[0]
if x > view_xview[0] + view_wview[0] x = view_xview[0] + view_wview[0]
if y < view_yview[0]                 y = view_yview[0]
if y > view_yview[0] + view_hview[0] y = view_yview[0] + view_hview[0]


This resets the x,y coordinates of the object to the edge of the screen, which is what you wanted right?
Logged

imaginationac
Level 2
**


Makin' games instead of makin' money.


View Profile WWW
« Reply #5 on: January 02, 2010, 01:29:55 PM »

Yes! That's precisely what I wanted! Thank you Theotherguy! Hand Thumbs Up Left
Logged

Youtube channel | Charger! Dev Log
              
pgil
Guest
« Reply #6 on: January 02, 2010, 01:34:32 PM »

Whoops. Yeah, Theotherguy's code is what I meant.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic