• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Problems with mp_grid_create

A

Ayumi Morris

Guest
Hi! I'm Ayumi and I'm making a racing game.

I was working on the pathfinding and found the mp_grid_create tool to make really choppy lines. This is the code I'm using and the size of the room:

Width: 2944
Height: 1664

globalvar rmgrass1;
rmgrass1 = mp_grid_create(0, 0, room_width, room_height, room_width/32, room_height/32);

The problem is, that the car animation looks REALLY choppy as it moves around. I'm using this for the angle at which the car points:


direction += angular_vel;
image_angle = direction;
angular_vel *= (1-angular_drag);

//compute new forward direction vector
y_hat = -sin(pi*direction/180);
x_hat = cos(pi*direction/180);


SO, here's the main problem. I thought I'd fix the choppiness by increasing the number of cells by decreasing cell width and cell height so that I divide them by 16 or even 8. But when I do that, the car doesn't move at all. The AI just stops working. Is there anything that I could do?
 

Dr_Nomz

Member
As it just so happens I am making a game with AI using this exact same concept:

That should make your cars look MUCH better, though it can be resource intensive with more than 50 units in your world, more so depending on it's size. (Seems fine in an environment of about 5000x5000 pixels large with 50 NPCs)

If you have any questions PM me and I'll try me best to explain the concepts. Oh, and you might need to adjust it to function for a vehicles particular behavior.
 
A

Ayumi Morris

Guest
I'll definitely try both of these things. Thank you for the advice!
 
A

Ayumi Morris

Guest
So I tried both methods of doing things, and it definitely smooths out the number of straight lines used. Do you know any way of making it so that it also stops the direction from changing so rapidly, and instead, having the image angle gradually change?
 

Dr_Nomz

Member
Haha no, I don't. xD But let me know if you figure that out.

Although if they are cars, then the turning is also gradual, right? Or did you not work that part out yet? Once you do it should be a lot easier for you to work that same code (I would think) into the image_angle portion of it. Feel free to post that here btw if you figured out the car part of it.
 
A

Ayumi Morris

Guest
Haha, yeah, I haven't exactly worked out the gradual turning on paths yet. I suppose that's what's keeping me from doing anything that looks good.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
So I tried both methods of doing things, and it definitely smooths out the number of straight lines used. Do you know any way of making it so that it also stops the direction from changing so rapidly, and instead, having the image angle gradually change?
Yup! Use the angle_difference() function... so something like:

Code:
var _diff = angle_difference(direction, direction_to_turn_to);
direction += median(-5, _diff, 5);
Might have the arguments round the wrong way, but that should be enough to get you started. You can change the 5/-5 to lower or higher values to make the turn speed quicker or slower too (if you just want to change the image_angle, then swap that for the direction variable in the code). :)
 
A

Ayumi Morris

Guest
I actually fixed it entirely by removing mp_grid_create and using a normal path. The problem, it seems, was that mp_grid_create only allows for things to be moved in straight lines, no matter how smooth they are, so the angle kept jumping in that direction.
 
Top