1 registered members (TipmyPip),
18,388
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Spherical gravity
#367729
04/17/11 08:49
04/17/11 08:49
|
Joined: May 2008
Posts: 2,113 NRW/Germany
alibaba
OP
Expert
|
OP
Expert
Joined: May 2008
Posts: 2,113
NRW/Germany
|
Hey people, I know that this was asked a lot of times. I use the code of JulzMighty. Thank you for that!  But the problem is, that the camera goes crazy. If i´m on a wall and just change the tilt angle, then it´s different than if i´m on ground. I hope you understand what i mean. If not, then i´ll upload a testlevel. Can someone make an example and provide it?
|
|
|
Re: Spherical gravity
[Re: 3run]
#367732
04/17/11 09:13
04/17/11 09:13
|
Joined: May 2008
Posts: 2,113 NRW/Germany
alibaba
OP
Expert
|
OP
Expert
Joined: May 2008
Posts: 2,113
NRW/Germany
|
Okay, i uploaded it. In this Version everything works fine, but i can´t look around with the camera. If you comment out the line "camera.tilt=my.tilt" and remove the double slash at "camera.tilt+=2*mouse_force.y" then you can look around, but only at the ground. If you walk up the Walls, the it´ll mess up. http://ifile.it/rqnx3po
|
|
|
Re: Spherical gravity
[Re: alibaba]
#367733
04/17/11 09:47
04/17/11 09:47
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
Here you go dude [FIXED AND TESTED]: Download link As I thought, problem wasn't with the camera  Main problem was adapting player's pan to normals)) BTW look at the script, I've made few improvements 
|
|
|
Re: Spherical gravity
[Re: alibaba]
#367742
04/17/11 13:25
04/17/11 13:25
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
I use the code of JulzMighty. Thank you for that!  You're welcome  I'm glad to see it in use! Try this new action:
action le()
{
player=me;
var relTilt = 0;
while(1)
{
gravitz();
c_rotate(my,vector(-2*mouse_force.x,0,0),GLIDE|IGNORE_PASSABLE|USE_AXISR);
c_move(my,vector((key_w-key_s)*20*time_step,(key_a-key_d)*20*time_step,walk_speed.z),nullvector,GLIDE | IGNORE_PASSABLE|IGNORE_FLAG2);
vec_set(camera.x,my.x);
relTilt = clamp(relTilt + 2 * mouse_force.y, -90, 90);
vec_set(camera.pan, vector(0, relTilt, 0));
ang_add(camera.pan, my.pan);
wait(1);
}
}
Also, I found the transitions much smoother when putting "time_step" as the last parameter to alignToVec(...) instead of 1, so you might want to try that out and see if that's what you want. Lastly, your gravits() function is a little bit risky. I think the first part should be "vec_set(runter.x, vector(0, 0, -20000)); vec_rotate(runter.x, my.pan); vec_add(runter.x, my.x);" The way it currently is, the direction of the trace depends on the entity's position. I hope that makes sense and is helpful  Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: Spherical gravity
[Re: JibbSmart]
#367747
04/17/11 15:21
04/17/11 15:21
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
OK, so that means that I've fixed another problem then  In the demo you showed, player completely can't walk on walls. I've fixed that as well as I've added smooth camera movement. Sorry that I've misunderstood main problem. I thought you can't make camera follow player. Anyway, Jibbs solution works well. Just make an offset tilt for main one. So here it is: Download link I move camera angles with key forces, change them as you like.
|
|
|
Re: Spherical gravity
[Re: 3run]
#367768
04/17/11 18:42
04/17/11 18:42
|
Joined: May 2008
Posts: 2,113 NRW/Germany
alibaba
OP
Expert
|
OP
Expert
Joined: May 2008
Posts: 2,113
NRW/Germany
|
@Julz I LOVE YOU!!!! (NO I´M NOT GAY  ) THIS WORKS GREAT!! YOU ARE AWESOME!! I´ve spended a lot of time to get this result! Awesome! Thank you!! @3run Thanks! But as my main problem is solved, i think i won´t need it and i already have my script  Thanks anyway  Maybe i find a way to use it YOU GUYS ARE GREAT!
|
|
|
Re: Spherical gravity
[Re: alibaba]
#367777
04/17/11 21:38
04/17/11 21:38
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
I'm glad it works well  You're welcome! I hope to see a really cool game come out of this! Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: Spherical gravity
[Re: JibbSmart]
#367794
04/18/11 13:01
04/18/11 13:01
|
Joined: May 2008
Posts: 2,113 NRW/Germany
alibaba
OP
Expert
|
OP
Expert
Joined: May 2008
Posts: 2,113
NRW/Germany
|
One more Question Julz, sorry that i am asking that much. But i somehow can´t solve this problem. I want, that my entity gets a target pan angle. the code is this:
#include <acknex.h>
#include <default.c>
VECTOR runter;
VECTOR walk_speed;
void alignToVec(ANGLE* entAng, VECTOR* vec, VECTOR* axis, var factor) {
vec_rotate(axis, entAng);
vec_normalize(axis, 1);
vec_normalize(vec, 1);
VECTOR rotAxis;
vec_cross(rotAxis, vec, axis);
var angle = -acosv(vec_dot(axis, vec))* factor * vec_length(rotAxis);
ANGLE rotAngle;
ang_for_axis(rotAngle, rotAxis, angle);
ang_add(entAng, rotAngle);
}
var oben=0;
ANGLE lo;
void gravitz()
{
vec_set(runter.x, vector(0, 0, -20000));
vec_rotate(runter.x, my.pan);
vec_add(runter.x, my.x);
my.skill96 = c_trace(my.x, runter.x,IGNORE_ME+IGNORE_SPRITES+USE_BOX+IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_FLAG2); // get maniac's height above the floor
if (my.skill96 > 2) // if I'm in the air
{
oben=1;
walk_speed.z -= 1*time_step; // gravity force pulls me down
}
else
{
oben=0;
walk_speed.z = 0; // if I'm on the ground, why worry
}
}
action le()
{
var relTilt = 0;
player=me;
VECTOR temp;
while(1)
{
gravitz();
if(key_space&&!oben)
walk_speed.z=5;
my.skill9=100*(key_k-key_l); //Target angle/ 100 or -100
alignToVec(my.pan, normal, vector(0, 0, 1), time_step);
c_rotate(my,vector(-ang(my.pan-my.skill9)*0.9*time_step,0,0),GLIDE);
c_move(my,vector((key_w-key_s)*20*time_step,(key_a-key_d)*20*time_step,walk_speed.z),nullvector,GLIDE | IGNORE_PASSABLE|IGNORE_FLAG2);
wait(1);
}
}
void main()
{
VECTOR camang;
level_load("test2.wmb");
ent_create("block.mdl",nullvector,le);
vec_set(camera.x,vector(-100,0,-50));
while(1)
{
vec_set(camang.x,player.x);
vec_sub(camang.x,camera.x);
vec_to_angle(camera.pan,camang.x);
wait(1);
}
}
What i´ve basically done is calculating the difference in the pan and the target angle and rotate it. But it somehow jerks around, when it´s on a wall.
|
|
|
|