Page 1 of 1

Sonic Game Abilities: Light Dash (Help please)

PostPosted: Mon Nov 12, 2012 5:15 am
by LyokoBlight
I'm making a Sonic game based on the Mach Speed sections in Sonic 06, I have lots of abilities included but I'm really having trouble with Light Dash.
Everytime I make it so he moves to the rings actor, he goes to a random one instead of the closest one :/
And when he does it he only goes to one ring and stops, can anyone help me so that he dashes along the closet trail of rings?

Thanks~
PS: By the way, just joined the forums. I've been making games for quite a long time now, but making Sonic games in Game Editor is tricky in my opinion.

Re: Sonic Game Abilities: Light Dash (Help please)

PostPosted: Mon Nov 12, 2012 7:43 am
by skydereign
LyokoBlight wrote:Everytime I make it so he moves to the rings actor, he goes to a random one instead of the closest one :/
And when he does it he only goes to one ring and stops, can anyone help me so that he dashes along the closet trail of rings?

It sounds like you already have code, so it'd be better if you posted it. That way we have a better idea of where you're coming from, and we can help correct it. It sounds like you are probably just using the default actor struct to access the position of the rings. If so this will access them in order of cloneindex, not position. And depending on how you align your rings, could appear to be random.

LyokoBlight wrote:PS: By the way, just joined the forums. I've been making games for quite a long time now, but making Sonic games in Game Editor is tricky in my opinion.

Welcome. Several attempts have been made to make a sonic game in gE, but as you said it is rather difficult. Namely setting up the running physics (loops and running up walls).

Re: Sonic Game Abilities: Light Dash (Help please)

PostPosted: Mon Nov 12, 2012 7:54 am
by LyokoBlight
Basically all I did was this-
Actor: SonicLightDash
Add Event > Draw Actor > Move To > Relative to Actor: +Rings
If you have any idea of some other way than that'd be great, because this isn't working out.
EDIT: Also, I made it so that SonicLightDash deletes itself and creates actor SonicMachFall when 'Collision Finishes'.
OFF TOPIC:
I should also mention there is a different actor for each of Sonic's actions, eg.
SonicMachRun
SonicMachJump
SonicMachSlide
SonicMachFall
SonicDashPanel
SonicDashRamp
etc.
I simply just find it easier to make different actors for each of them.

Re: Sonic Game Abilities: Light Dash (Help please)

PostPosted: Mon Nov 12, 2012 9:04 am
by skydereign
LyokoBlight wrote:Basically all I did was this-
Actor: SonicLightDash
Add Event > Draw Actor > Move To > Relative to Actor: +Rings
If you have any idea of some other way than that'd be great, because this isn't working out.

You need a way of telling the game which ring actor is the closest. Currently there isn't a very good way of doing that. You can go about it one of two ways. The best way is to try to loop through all of the rings, finding the closest one. This can be a bit problematic though because you can't get a list of all clones of a given type. I plan to implement this for the next version of gE, but for now the method of doing it is a bit of a hack.

You need to loop through all clones between the lowest cloneindex and the highest cloneindex. There isn't a way of accessing the highest cloneindex, so we'll need to create a variable to hold that value. In this case I am calling it ring_max. The following line of code will set the ring_max variable to the clone's index.
Rings -> Create Actor -> Script Editor
Code: Select all
ring_max = cloneindex;

One thing to note is that a clone created will always have the highest cloneindex of the actor type. So if you had clones [0, 1, 6, 92] the newly created clone would have an index of 93. The only exception to this is if the actor is not created with the CreateActor function. That is to say if you create it on the stage with the editor. If you are doing this, it won't be as efficient, but you can use this instead.
Rings -> Create Actor -> Script Editor
Code: Select all
ring_max = max(ring_max, cloneindex);


Now to find the closest ring you'll need to add this function into global code.
Global Code
Code: Select all
Actor*
getclone2 (char* name, int cindex)
{
    char buffer[30];
    sprintf(buffer, "%s.%d", name, cindex);
    return(getclone(buffer));
}


And finally to move to the closest ring, you can do something like this.
Code: Select all
int dist = distance(x, y, Rings.x, Rings.y); // this gets the distance to the lowest indexed ring
int idx = Rings.index;
// we need it as a base, and we use idx to determine which clone
Actor* temp; // used to store an actor
int i = 0;

for(i=Rings.index;i<ring_max;i++)
{
    temp = getclone2("Rings", i); // get clone Rings.i
    if(temp->cloneindex!=-1 && distance(x, y, temp->x, temp->y)<dist) // valid clone and is closer
    {
        dist = distance(x, y, temp->x, temp->y);
        idx = temp->cloneindex;
    }
}

temp = getclone2("Rings", idx); // get closest ring
if(temp->cloneindex!=-1) // if the clone is valid
{
    MoveTo("Event Actor", temp->x, temp->y, 10, "(none)", "(none)");
}

It is a tad on the complex side, so if you want anything explained ask. An important thing to note... not all clones from the lowest to highest indexes will exist, so to check if the clone exists, you can check to see if its cloneindex is not -1. I wouldn't recommend putting that code in the actor's draw event, because each frame it will have to loop through every ring, which depending on your game, could be a lot of actors.

Re: Sonic Game Abilities: Light Dash (Help please)

PostPosted: Tue Nov 13, 2012 8:46 am
by LyokoBlight
Holy-

That is way more technical than anything I do in Game Editor, which just makes me all the more interested.
I'LL FIGURE THIS OUT SOMEHOW.
If I do have any problems/don't understand something, may I send a private message asking for assistance?

Thanks for the help, I really appreciate it.

Re: Sonic Game Abilities: Light Dash (Help please)

PostPosted: Tue Nov 13, 2012 9:05 pm
by skydereign
LyokoBlight wrote:If I do have any problems/don't understand something, may I send a private message asking for assistance?

Feel free. It definitely is on the more complex side of gE.