Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411423 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 19, 2024, 05:05:21 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Intersection/crossroad problem
Pages: [1]
Print
Author Topic: Intersection/crossroad problem  (Read 766 times)
lvldesignII
Level 0
**


View Profile
« on: September 14, 2015, 01:44:46 AM »

Hello all,

I'm having a little problem I'm hoping some of you guys could help out with.  Smiley I'm trying to create an overworld map like Mario's overworld map for my little game. I'm doing this with invisible walls that stop the player leaving the path, this mostly works good but I'm having a problem with stopping the player at an intersection/crossroad.

For the player object:

Code:
//Create

movespd = 4;
spd = movespd;

//Step

//movement
if (up) {
    direction = 90;
    spd = movespd;

//collisions

if (spd > 0) {
    var iwall;
    switch (direction) {
        // moving right
        case 0:
        x += spd;
        iwall = instance_place(x, y, obj_block);
        if (iwall != noone) {
            spd = 0;
            x -= bbox_right - iwall.bbox_left + 1;
        }
        break;

etc.


Movement works fine but the player doesn't stop at an intersection so I created an intersec object and placed it at the intersections with the following code:

Code:

if instance_place(x, y-31, obj_player) {
    obj_player.spd = 0;
}


Here's the problem the player stops at an intersection/crossroad but when I try to move the player again it jumps 4 pixel in the given direction then stops. If I continue to try move it keeps jumping until I'm no longer having a collision with the intersec object then moves normally in the given direction.

I know what's causing the problem but I'm not to sure on how to fix it.

Any ideas?  Shrug
Logged
ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #1 on: September 14, 2015, 08:17:59 AM »

Do you need free movement? Mario game map screens were essentially traversing nodes on a graph, with no meaningful in-between state other than a noninteractive walking animation. Instead of collision tests, I'd probably do this with a completely different structure, where each place you can stop knows which directions are valid for movement, and animates to the next stopping place when you press one of those directions.
Logged

diegzumillo
Level 10
*****


This avatar is so old I still have a some hair


View Profile WWW
« Reply #2 on: September 14, 2015, 12:44:11 PM »

/\ what he said. Mario's overworld is basically a fancy menu.
Logged

lvldesignII
Level 0
**


View Profile
« Reply #3 on: September 15, 2015, 01:49:41 AM »

Do you need free movement? Mario game map screens were essentially traversing nodes on a graph, with no meaningful in-between state other than a noninteractive walking animation. Instead of collision tests, I'd probably do this with a completely different structure, where each place you can stop knows which directions are valid for movement, and animates to the next stopping place when you press one of those directions.

Hmm, I thought about doing something similar but not really sure how to do it (still learning), I used this method because it's something I understand.

So how would I do something like your suggestion, have my player on a node and then on the node object have code saying if the player is on the node and a key is pressed keep moving until he lands on a new node etc?







Logged
lvldesignII
Level 0
**


View Profile
« Reply #4 on: September 18, 2015, 06:33:21 PM »

Code:
Okay, I'm still having a problem with intersections , I tried using ThemsAllTook method I think  :shrug2: so changed the code to:

[code]

In the Node object

if (instance_place(x, y, obj_player)) { //if the player is on the node
    if keyboard_check(vk_up) { // if we pressed up
        with (obj_player) { //with the player
            move_towards_point(obj_node1.x, obj_node1.y, 4); // move to a new node
        }
    }   
}
etc.

Code:

In the player

if (place_meeting(x, y-31, obj_node) // stop on the node

the problem original problem remains, when I move from one node to a intersection node, the player stops on target then when I try to move again the player moves and stops.

Code:
if (place_meeting(x, y-31, obj_node) // stop on the node

[/code]

I think because this code block is always checking for collision it's what's causing the problem.

Any help would be great.  Smiley



Logged
moomat
Level 0
***



View Profile WWW
« Reply #5 on: September 19, 2015, 02:18:20 PM »

So how would I do something like your suggestion, have my player on a node and then on the node object have code saying if the player is on the node and a key is pressed keep moving until he lands on a new node etc?

That would depend a lot on how the game you're working on is set up, but the basic premise would be that you'd had like an array or a vector of locations, and when you hit the "up" key you tween the player movement to the next location in your array (obviously you'd need some way of cycling through the array, whether it be by using an iterator or whatever). You could use some implementation of the tweening functions here, even: http://easings.net/

You're thinking of it like "the left key moves the player left" when, at least if the previous suggestion works for your game, you'd have to think about it more like "on pressing the left key, cycle to the next location in my locations array."
Logged

Check out Junk E.T. at junketgame.com

lvldesignII
Level 0
**


View Profile
« Reply #6 on: September 19, 2015, 07:26:06 PM »

So how would I do something like your suggestion, have my player on a node and then on the node object have code saying if the player is on the node and a key is pressed keep moving until he lands on a new node etc?

That would depend a lot on how the game you're working on is set up, but the basic premise would be that you'd had like an array or a vector of locations, and when you hit the "up" key you tween the player movement to the next location in your array (obviously you'd need some way of cycling through the array, whether it be by using an iterator or whatever). You could use some implementation of the tweening functions here, even: http://easings.net/

You're thinking of it like "the left key moves the player left" when, at least if the previous suggestion works for your game, you'd have to think about it more like "on pressing the left key, cycle to the next location in my locations array."

Okay I'll try it this way. Thanks.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic