#2561 posted by Reyond on 2018/07/05 19:58:41
Sure, I heard of Parachute in Malice, but that is not really what I need. I also should work with horizontal velocity and vertical velocity to make dependence between them like in real glider. I don’t need just to “slow down falling”
I Thought Wings
#2562 posted by Qmaster on 2018/07/05 22:15:35
...thought wings were in Nehahra. Every time you tapped jump you lurched up a bit and you slowly drifted back down. Kind of like an infinite double jump.
#2563 posted by Qmaster on 2018/07/05 22:17:06
You could also set player .gravity to something like 0.4 or 0.5.
#2564 posted by mankrip on 2018/07/06 00:38:13
What you want is a MOVETYPE_FLY that's slightly affected by gravity, and with lower friction.
I don't know if sv_friction affects MOVETYPE_FLY, or if the aerial friction is hardcoded.
#2565 posted by Reyond on 2018/07/06 23:06:56
I thought about things that should be realized so it could work:
1. I should make flight vector. This vector should follow view angle vector but with a small delay. That makes our flight more realistic. Also it allows to set maneuvering.
2. When player falls down he accelerate, when he looks forward he slows down.
I have some suggestions how it can be done:
1. vector fly_direction, float m;
makevectors(fly_direction);
makevectors(self.v_angle);
if(fly_direction != self.v_angle)
{
if(fly_direction_x != self.v_angle_x)
{
fly_direction_x += (self.v_angle_x - fly_direction_x)/m;
}
if(fly_direction_y != self.v_angle_y)
{
fly_direction_y += (self.v_angle_y - fly_direction_x)/m;
}
}
//acceleration
float coef;
//fly acceleration coefficient
coef = ((self.v_angle_x-45)/90);
velocity=acceleration*coef;
#2566 posted by Reyond on 2018/07/06 23:07:51
Please help me to translate that into quakeC properly
Possible Version
#2567 posted by Preach on 2018/07/07 10:52:07
Here's what I'd do, roughly:
//convert current velocity into speed and direction
speed = vlen(self.velocity);
olddir = normalise(self.velocity);
//convert angles into a normalised heading
makevectors(self.y_angle);
//add a small amount of the heading to the current direction of travel
newdir = normalise( v_forward*frametime + olddir*(1-frametime));
//preserve the speed we had, but change the direction
self.velocity = newdir * speed;
//reduce the strength of gravity based on how level we are currently flying
self.gravity = 0.1 + 0.9*abs(v_forward*'0 0 1');
Some of the values might need tuning here and there, but that should get you started. Player movetype should be left as default, because we want gravity to apply (subject to the last line reducing how fast we fall. Haven't tested this, so it may be rubbish...
Correction
#2568 posted by Preach on 2018/07/07 10:53:26
makevectors(self.y_angle);
should of course be
makevectors(self.v_angle);
#2569 posted by Spike on 2018/07/07 13:34:19
use dotproducts:
upspeed = self.velocity * v_up;
fwdspeed = self.velocity * v_forward;
rightspeed = self.velocity * v_right;
(vec*vec is a dotproduct).
You can then get back to the original velocity vector with:
self.velocity = v_up*upspeed + v_forward*fwdspeed + v_right*rightspeed;
Of course, if you change some fraction of the force exerted on the underside of your glider before reforming the velocity then you'll reduce the effects of gravity while horizontal, and return to normal when facing vertically down.
Of course, that energy should normally go somewhere - if you add to fwdspeed anything you subtract from upspeed then you should get something a bit glidery.
you'll also need to include some friction somewhere, in order to get some terminal velocity. and yeah, the conversion should probably also not be 100% efficient either, nor should it convert ALL the energy.
but yeah, dotproducts are great if you want to compare two directions. trying to do stuff like this without using them is just going to leave it feeling really hacky.
Unfortunately there's no real way to control the camera from ssqc, but csqc can override the camera angles without changing the client's 'desired' angles. you should be able to implement roll that way, somehow.
Notes After Testing The Suggested Code
#2570 posted by Preach on 2018/07/09 00:20:50
Had a go with the code from my post on Saturday, it worked pretty well for a first attempt. I did find that it wasn't responsive enough until I doubled frametime everywhere it appeared. One big tip for testing it - use e1m8. Firstly because its one of the few ID maps with enough vertical and horizontal space to glide in properly, secondly because it's low gravity so it's much more fun!
It's got most of the effects you'd want to see in glider physics - you can dive down to gain speed then level off and carry the momentum forward, and if you look up you'll gain height but bleed forward speed. You can look straight up, and you'll quickly stall then crash to the ground. Also if you collide with walls etc your speed is lost which tends to end the flight pretty quick.
One advanced trick: you can accelerate in Quake while in the air. If you're gliding, strafe left while turning in an anticlockwise circle and you'll gain speed (same principle as bunnyhopping works on). You can use this to offset the loss of speed while climbing, and gain height by moving in a big spiral.
Preach’s Code Test
#2571 posted by Reyond on 2018/07/09 08:29:44
Hi Preach, yesterday I arrived to my PC and I got an error after compiling your code. May be I have done something wrong. Could you please post a full file with your code so I could test it out? I think that would be useful for all the community.
#2572 posted by c0burn on 2018/07/09 18:21:41
Maybe if you post the error you're getting we can help you out ...
Skeleton Code
#2573 posted by Preach on 2018/07/09 20:54:12
I tried to post it as skeleton code so that you'd get some practice hooking it up. One thing I did unintentionally was to misspell (well, anglicize) a built-in function name, so make sure you change the spelling to normalize. If that wasn't the error that's stopped you, post it like c0burn says and we can suggest fixes.
#2574 posted by Reyond on 2018/07/10 12:21:21
Still no result. I try to use this code if no flag on_ground is false but nothing works.
New Issue
#2575 posted by Preach on 2018/07/10 23:34:43
Hi Reyond. It sounds like it's a bit further on if the compiler error has gone away. What function are you running the code in? I ran it in PlayerPreThink so that it would happen every frame. You're right to disable the code when the player is on the ground, but from your description I don't know whether the code you have is right.
I used: if(self.flags & FL_ONGROUND) to see if the player was on the ground. I also turned the code off while the player was in water using the check if(self.waterlevel) (although that's a detail to add once the basics work.
If that doesn't help, post the whole text of the code you're using and maybe we can spot what else it could be...
Tut From InsideQc
#2576 posted by madfox on 2018/07/11 14:37:59
Found an old tutorial from Legion with an Xman version of a FlySimulator. Maybe helpfull as a guide.
#2577 posted by Reyond on 2018/07/12 01:26:51
Allright, I found an error. Here is how I use the code:
else // airborn
{
vector fly_direction; vector new_dir; float fly_speed;
float fly_velocity; '
float koef;
/*
if (wishspeed < 30)
f = wishspeed - (self.velocity * wishdir);
else
f = 30 - (self.velocity * wishdir);
if (f > 0)
self.velocity - self.velocity + wishdir * (min(f, sv_accelerate) * wishspeed * frametime);
*/
fly_speed = vlen(self.velocity);
fly_direction = normalize(self.velocity);
makevectors(self.v_angle);
new_dir = normalize(v_forward*frametime +fly_direction*(1-frametime)); self.velocity = new_dir * speed;
}
#2578 posted by Reyond on 2018/07/12 01:32:54
Yes, actually it looks a little bit like gliding but I can’t understand how the code works. Why do I use frametime if this function works every frame? How this code affects the gravity (in-game gravity is 100 now). And how can I improve this code to make it work better?
Also, I would like to make it works without changing the standart “800” value of the sv_gravity variable. Is that possible?
Also, thanks to Preach and to everyone who helps me in making player gliding in quake.
Try It Out
#2579 posted by Preach on 2018/07/12 22:56:06
Have a go with the second-to-last line changed to
new_dir = v_forward;
This leaves out the bits with frametime. What you should notice is that while gliding, you instantly start moving in exactly the direction you are facing. It's very easy to control, but it's not very realistic for a glider - you can 180 turn instantly at any time.
The idea behind the frametime code is to add the v_forward part more slowly, so that your direction of travel doesn't change instantly. Instead we add the v_forward in a bit at a time. Because the function runs every frame, we need the pieces we add to be smaller when the framerate is higher, otherwise people with higher framerates could execute tighter turns, which would be unfair.
I found that in practice the rate of change was too slow, and that it was better to change that line to:
new_dir = normalize(v_forward*2*frametime +fly_direction*(1-2*frametime));
By making the piece we add each frame twice as large, we get a better trade-off between smooth turning and reaction time.
In terms of making the glider float, I noticed that you don't have the last line from the code I posted:
self.gravity = 0.1 + 0.9*abs(v_forward*'0 0 1');
I expect you were getting a compiler error from this line that you didn't know how to fix. The secret is to add the following to the bottom of defs.qc:
.float gravity;
This warns the compiler that you'd like to be able to store a float called "gravity" on all the entities. The engine uses this to change the gravity just for that entity. So if you are flying in normal 800 strength gravity, but the player has self.gravity = 0.1, for that player gravity will be 80 instead (because 800 * 0.1 = 80). All other entities are unaffected, try firing a grenade while gliding and notice that it falls normally.
Give it a go, see what comes of it! Any more questions, just ask...
#2580 posted by Reyond on 2018/07/12 23:08:01
Error: unknown value “abs”.
To Reyond
its fabs i think
Yup
#2582 posted by Preach on 2018/07/13 00:13:06
Teach me to copy-paste from the sketchy untested post rather than the working code, use fabs and it'll work.
#2583 posted by Reyond on 2018/07/13 18:15:40
Finally, we have a nice result!
Watch this:
https://youtu.be/vuXm64C_xso
Thanks to Preach for the code and to st1x51, Baker, madfox, metlslime, Qmaster, Spike, mankrip, c0burn and to all who helped me with this.
Here you can get progs.dat file to check it out:
https://drive.google.com/open?id=1U1Qb6nN3nTc9zwpRYZotGen_weFsBjIQ
And here is the source code (use dpextensions.qc or fteextensions.qc to compile it and add .float gravity in to the defs.qc):
https://drive.google.com/open?id=1Mck52dhvC7KKKOkC2N3QzGcgiBqQJtQU
Reyond
#2584 posted by Baker on 2018/07/13 18:59:17
Tried in on E1M7 in FTE and it works nice.
Congrats!
Improving The Code
#2585 posted by Reyond on 2018/07/14 13:49:43
Is there any way to slow down flight? I have to make huge maps to make flight works properly.
And is there any way to change the value of horizontal speed loss?
Is there any way to make this work in standard quake without ising fork engines extensions?
|