Log in
Search
GameML File Sharing
USERNAME: gamemladmin@gmail.com PASSWORD: gamemlsite Upload Here: https://gameml.forumotion.com/GameML-File-Sharing-h3.htmPlease add only games.why use parenting?
3 posters
:: Game Making :: Game Maker Help :: Code Database :: GameMaker Techniques
Page 1 of 1
why use parenting?
parenting is useful when you want to have alot of objects that do almost the same thing. or when you want to the same with a bunch of objects but don't feel like copying and rewriting code for them all.
you should read "More About Objects" in the gm manual. if you haven't read it, go read it now.
i want to make a 3d game. i want solid objects but when i use gm's build in solid, the player will be moved to its previous position when it collides with a wall. i will make a parent object called par_solid so i can do collision checks with any of its children. par_solid objects will use their sprite, a z, and a height variable. i set those varibales in the create event of the children.
i want the player to slide smoothly. i will make a 2 scripts, d3d_instance_place and reduce.
d3d_instance_place
step
the while loops say, "while there is a solid ahead of me, reduce speed. if i'm stopped, stop the loop."
using the par_solid object i can make children that are different sizes and i won't have to do any more coding or collision events. here is an example gmk that uses this technique.
learn 3d example
i will make this post better if it is confusing.
you should read "More About Objects" in the gm manual. if you haven't read it, go read it now.
i want to make a 3d game. i want solid objects but when i use gm's build in solid, the player will be moved to its previous position when it collides with a wall. i will make a parent object called par_solid so i can do collision checks with any of its children. par_solid objects will use their sprite, a z, and a height variable. i set those varibales in the create event of the children.
i want the player to slide smoothly. i will make a 2 scripts, d3d_instance_place and reduce.
d3d_instance_place
- Code:
//
// Arguments:
// x
// y
// z
// obj
//
// Returns:
// whether the instance placed at position (x,y,z) meets obj.
// obj can be an object in which case the function returns
// true is some instance of that object is met. It can also
// be an instance id, the special word all meaning an
// instance of any object, or the special word other.
//
// slayer 64
//
with(argument3)
{
with(other)
{
if place_meeting(argument0,argument1,other)
if argument2+height-1>=other.z
if argument2 <=other.z+other.height-1
if id!=other.id
return 1;
}
}
return 0;
- Code:
//
// arguments:
// number
//
// returns:
// the number reduced closer to 0
//
// slayer 64
//
return floor(abs(argument0)/2)*sign(argument0);
step
- Code:
while(d3d_place_meeting(x+hspeed,y,z,par_solid))
{
hspeed=reduce(hspeed);
if hspeed=0 break;
}
while(d3d_place_meeting(x+hspeed,y+vspeed,z,par_solid))
{
vspeed=reduce(vspeed);
if vspeed=0 break;
}
while(d3d_place_meeting(x+hspeed,y+vspeed,z+zspeed,par_solid))
{
zspeed=reduce(zspeed);
if zspeed=0 break;
}
the while loops say, "while there is a solid ahead of me, reduce speed. if i'm stopped, stop the loop."
using the par_solid object i can make children that are different sizes and i won't have to do any more coding or collision events. here is an example gmk that uses this technique.
learn 3d example
i will make this post better if it is confusing.
slayer 64- GameML Noob
- Posts : 20
Points : 54285
GameML Reputation : 8
Join date : 2009-07-05
Age : 34
Re: why use parenting?
Whoa! Slayer 64 joined! Now we have some people that actually know about GameMaker This looked like a pretty in depth desription, but I can't really tell because I know nothing about 3D programing.
Re: why use parenting?
It is good, parenting is a great thing to do in 3d games, which im adding to mine now.
:: Game Making :: Game Maker Help :: Code Database :: GameMaker Techniques
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|