|
Give me gravity please
#241602
12/17/08 14:34
12/17/08 14:34
|
Joined: Nov 2007
Posts: 1,032 Croatia
croman
OP
Serious User
|
OP
Serious User
Joined: Nov 2007
Posts: 1,032
Croatia
|
Hi,
Does anyone have a gravity script that is working? It doesnt matter if it's lite-c or c-script(i'll convert it) just that it's a working gravity script. Please...:)
Thnx
Ubi bene, ibi Patria.
|
|
|
Re: Give me gravity please
[Re: croman]
#241609
12/17/08 15:58
12/17/08 15:58
|
Joined: Aug 2003
Posts: 7,439 Red Dwarf
Michael_Schwarz
Senior Expert
|
Senior Expert
Joined: Aug 2003
Posts: 7,439
Red Dwarf
|
c_move(me, vector(0,0,-9), nullvector, IGNORE_ME);
"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
|
|
|
Re: Give me gravity please
[Re: Michael_Schwarz]
#241611
12/17/08 16:26
12/17/08 16:26
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
Mathematically it should be: y(t) == y(0) + v(0) t + (1/2) g t2 where: * y(t), height depending on time; * y(0), starting height; * v(0), starting speed; * g, acceleration ( gravitational acceleration g is 9.98 on earth, 3.73 on mars); * t, time. In the example of a falling panel: if (falling == true) {
panel.pos_y = fallheight + (0 * falltime) + 0.5 * 9.98 * (falltime*falltime); //gravity formula, change (0 * falltime) for giving an initial speed
falltime += time_step; //falltime is counting
}
if (falling == false) {
falltime = 0; //reset falltime
fallheight = panel.pos_y; //record height as long as we're on ground, can then be used as initial height when in the air
}
Last edited by Joozey; 12/17/08 16:44.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Re: Give me gravity please
[Re: Joozey]
#241615
12/17/08 16:53
12/17/08 16:53
|
Joined: Nov 2007
Posts: 1,032 Croatia
croman
OP
Serious User
|
OP
Serious User
Joined: Nov 2007
Posts: 1,032
Croatia
|
thnx. i'll try to implement that method but i hoped that someone has a piece of code with c_trace and c_move and everything else for gravity
Ubi bene, ibi Patria.
|
|
|
Re: Give me gravity please
[Re: Joozey]
#241619
12/17/08 17:13
12/17/08 17:13
|
Joined: Nov 2007
Posts: 1,032 Croatia
croman
OP
Serious User
|
OP
Serious User
Joined: Nov 2007
Posts: 1,032
Croatia
|
i tried :P i stuck quite often. i even tried to use that khmovement gravity but it has some major problems with lite-c - dont know why well it seems i'll use yours approach
Ubi bene, ibi Patria.
|
|
|
Re: Give me gravity please
[Re: croman]
#241621
12/17/08 17:29
12/17/08 17:29
|
Joined: Oct 2007
Posts: 5,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
|
this was from Davids khmovement tut i guess(only the gravity part)
#define jumping_height 20
vec_set(vec1_from,my.x);
vec_set(vec1_to,my.x);
vec1_to.z -= 1000;
height = c_trace(vec1_from, vec1_to,IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES|USE_BOX);
if (key_space)
{
if (height < 2)
{
height = 1;
move_vec.z = jumping_height*time_step;
}
}
if (height > 0)
{
move_vec.z-=3 * time_step;
if (move_vec.z < (height * -1))
{
move_vec.z = height * -1;
}
}
else
{
move_vec.z = -1 * height;
}
c_move(me, move_vec, nullvector,GLIDE|IGNORE_SPRITES|IGNORE_PASSABLE|USE_BOX);
you have to definfe move_vec,height and such ofc.
Last edited by Quadraxas; 12/17/08 17:29.
3333333333
|
|
|
Re: Give me gravity please
[Re: Xarthor]
#241624
12/17/08 17:53
12/17/08 17:53
|
Joined: Nov 2007
Posts: 1,032 Croatia
croman
OP
Serious User
|
OP
Serious User
Joined: Nov 2007
Posts: 1,032
Croatia
|
thnx Quadraxas
Xarthot, i will. can you explain why exactly?
Ubi bene, ibi Patria.
|
|
|
|