Phantom107 Forum

Phantom107's Forum. Discuss about games, GML, 3d, game design here. Enjoy your stay ;)
 
HomeFAQSearchRegisterMemberlistUsergroupsLog in

Share | 
 

 motion my way

Go down 
AuthorMessage
slayer64
Heavy Poster
avatar

Posts : 143
Join date : 2008-01-05

PostSubject: 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?
Back to top Go down
View user profile
Phantom107
Admin
avatar

Posts : 206
Join date : 2008-01-03
Location : The Netherlands

PostSubject: 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
Back to top Go down
View user profile http://phantom107.actieforum.com
slayer64
Heavy Poster
avatar

Posts : 143
Join date : 2008-01-05

PostSubject: 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.
Back to top Go down
View user profile
Phantom107
Admin
avatar

Posts : 206
Join date : 2008-01-03
Location : The Netherlands

PostSubject: Re: motion my way   Sat Jan 05, 2008 3:16 am

I didn't say it was faster Wink

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?
Back to top Go down
View user profile http://phantom107.actieforum.com
stewrat
Loyal Poster
avatar

Posts : 78
Join date : 2008-01-04

PostSubject: never mind   Sat Jan 05, 2008 5:12 am

never mind


Last edited by on Thu Jan 10, 2008 1:37 am; edited 1 time in total
Back to top Go down
View user profile http://www.yogamerclub.piczo.com
slayer64
Heavy Poster
avatar

Posts : 143
Join date : 2008-01-05

PostSubject: Re: motion my way   Sat Jan 05, 2008 5:16 am

lets hear it.
Back to top Go down
View user profile
Guilty Sparks
Heavy Poster
avatar

Posts : 154
Join date : 2008-01-05
Location : USA East Coast

PostSubject: 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 Very Happy And if its a game in space or underwater, you would have to decrease your speed and increase how high you jump. lol!
Back to top Go down
View user profile
slayer64
Heavy Poster
avatar

Posts : 143
Join date : 2008-01-05

PostSubject: 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?
Back to top Go down
View user profile
Guilty Sparks
Heavy Poster
avatar

Posts : 154
Join date : 2008-01-05
Location : USA East Coast

PostSubject: 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.
Back to top Go down
View user profile
Phantom107
Admin
avatar

Posts : 206
Join date : 2008-01-03
Location : The Netherlands

PostSubject: 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
Back to top Go down
View user profile http://phantom107.actieforum.com
Watever742
Active Member
avatar

Posts : 39
Join date : 2008-01-21

PostSubject: Re: motion my way   Sat Feb 02, 2008 6:07 am

he has a point
Back to top Go down
View user profile
slayer64
Heavy Poster
avatar

Posts : 143
Join date : 2008-01-05

PostSubject: 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! affraid
Back to top Go down
View user profile
Phantom107
Admin
avatar

Posts : 206
Join date : 2008-01-03
Location : The Netherlands

PostSubject: 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;
Back to top Go down
View user profile http://phantom107.actieforum.com
Sponsored content




PostSubject: Re: motion my way   

Back to top Go down
 
motion my way
Back to top 
Page 1 of 1
 Similar topics
-
» Abortants for Silent Migraine/Chronic Daily Headache?

Permissions in this forum:You cannot reply to topics in this forum
Phantom107 Forum :: Techniques-
Jump to: