| motion my way | |
|
|
Author | Message |
---|
slayer64 Heavy Poster
Posts : 143 Join date : 2008-01-05
| Subject: motion my way Sat Jan 05, 2008 2:51 am | |
| here is how i make motion for moving in FPS and other things KEYBOARD A EVENT - Code:
-
hspeed+=lengthdir_x(1,dir+90); vspeed+=lengthdir_y(1,dir+90); KEYBOARD S EVENT - Code:
-
hspeed+=lengthdir_x(1,dir+180); vspeed+=lengthdir_y(1,dir+180);
KEYBOARD D EVENT - Code:
-
hspeed+=lengthdir_x(1,dir-90); vspeed+=lengthdir_y(1,dir-90); KEYBOARD W EVENT - Code:
-
hspeed+=lengthdir_x(1,dir); vspeed+=lengthdir_y(1,dir); dir is the direction the camera is facing. this code will add 1 to the speed in any direction. is this good code or not? | |
|
| |
Phantom107 Admin
Posts : 206 Join date : 2008-01-03 Location : The Netherlands
| Subject: Re: motion my way Sat Jan 05, 2008 3:06 am | |
| Well I guess the code should work, but I prefer to work with the speed and direction variables instead of hspeed and vspeed. An example is found here. If you want to use the hspeed and vspeed variables, the only thing I would do is to clean the code up. I hate having a lot of events. This is how I would do it: - Code:
-
//execute in the step event if keyboard_check(ord('A')) { hspeed += lengthdir_x(1,dir+90); vspeed += lengthdir_y(1,dir+90); }
if keyboard_check(ord('S')) { hspeed += lengthdir_x(1,dir+180); vspeed += lengthdir_y(1,dir+180); }
if keyboard_check(ord('D')) { hspeed += lengthdir_x(1,dir-90); vspeed += lengthdir_y(1,dir-90); }
if keyboard_check(ord('W')) { hspeed += lengthdir_x(1,dir); vspeed += lengthdir_y(1,dir); } - Phantom107 | |
|
| |
slayer64 Heavy Poster
Posts : 143 Join date : 2008-01-05
| Subject: Re: motion my way Sat Jan 05, 2008 3:10 am | |
| isn't that code EXACTLY the same? why would game maker be faster if the code is in the step event? i mean game maker is EVENT driven. i'd rather have game maker go through its events the way its was meant to. there MUST be a way to test this. it must be TESTED. | |
|
| |
Phantom107 Admin
Posts : 206 Join date : 2008-01-03 Location : The Netherlands
| Subject: Re: motion my way Sat Jan 05, 2008 3:16 am | |
| I didn't say it was faster I'm not sure, but I think when, for example, you put a "keyboard check w" event in the object, gamemaker will check for it every step. Otherwise it won't (I think). Checking it manually in the step event will consume precisely the same I presume? | |
|
| |
stewrat Loyal Poster
Posts : 78 Join date : 2008-01-04
| Subject: never mind Sat Jan 05, 2008 5:12 am | |
|
Last edited by on Thu Jan 10, 2008 1:37 am; edited 1 time in total | |
|
| |
slayer64 Heavy Poster
Posts : 143 Join date : 2008-01-05
| Subject: Re: motion my way Sat Jan 05, 2008 5:16 am | |
| | |
|
| |
Guilty Sparks Heavy Poster
Posts : 154 Join date : 2008-01-05 Location : USA East Coast
| Subject: Re: motion my way Sat Jan 05, 2008 3:53 pm | |
| Those codes look like they'll work, although I use different ones... Also, wouldnt the type of game matter in motion? If its a plane game, then I dont think you can use those And if its a game in space or underwater, you would have to decrease your speed and increase how high you jump. | |
|
| |
slayer64 Heavy Poster
Posts : 143 Join date : 2008-01-05
| Subject: Re: motion my way Sun Jan 06, 2008 3:16 am | |
| the code is meant for top down movement. great 4 3d games. what does your code look like Guilty Sparks? | |
|
| |
Guilty Sparks Heavy Poster
Posts : 154 Join date : 2008-01-05 Location : USA East Coast
| Subject: Re: motion my way Sun Jan 06, 2008 3:35 pm | |
| oh, I was talking about 3d... And my code varries on depending what type of game, wether it is third person or first. | |
|
| |
Phantom107 Admin
Posts : 206 Join date : 2008-01-03 Location : The Netherlands
| Subject: Re: motion my way Sun Jan 06, 2008 4:53 pm | |
| @ slayer64
There are 2 things that'll improve your motion code: 1) Add friction. This will make more smooth movement. 2) Set a maximum speed | |
|
| |
Watever742 Active Member
Posts : 39 Join date : 2008-01-21
| Subject: Re: motion my way Sat Feb 02, 2008 6:07 am | |
| | |
|
| |
slayer64 Heavy Poster
Posts : 143 Join date : 2008-01-05
| Subject: Re: motion my way Sat Feb 02, 2008 6:51 am | |
| yes phantom, add those things would be a good idea. i could also say - Code:
-
speed/=1.1; this will add friction and a maximum speed at the same time. no way! | |
|
| |
Phantom107 Admin
Posts : 206 Join date : 2008-01-03 Location : The Netherlands
| Subject: Re: motion my way Sat Feb 02, 2008 2:06 pm | |
| While it works, using this technique the friction depends on the maximum speed and vice versa. Since you're using hspeed and vspeed, the friction variable will work too so you can seperate max speed and friction. like this: - Code:
-
friction = 0.05; if speed > 5 then speed = 5;
| |
|
| |
Sponsored content
| Subject: Re: motion my way | |
| |
|
| |
| motion my way | |
|