1 registered members (TipmyPip),
18,388
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Bumping Your Head Physics
#383694
09/24/11 00:47
09/24/11 00:47
|
Joined: Mar 2009
Posts: 186
Valdsator
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 186
|
I'm trying to detect when a player bumps their head on a ceiling or object above them when they jump, so I can reduce z_move to 0, so rather than being stuck on the ceiling for a bit before gravity pulls them down, they'll fall immediatly. I'm currently doing this with a c_trace, but because that's a line, it's inaccurate, and it's also a "Slow" command (which I think should be fine, but perhaps there's another way). I'm thinking I should use a c_scan so no matter what part of the player's head touches the ceiling, it will reduce z_move to 0, but that's also a "Slow" command, and I feel like c_scan would be a lot slower than c_trace. Is there another way to accomplish this? I'm willing to use c_scan, I'm just not sure if that's very efficient.
|
|
|
Re: Bumping Your Head Physics
[Re: Valdsator]
#383696
09/24/11 01:01
09/24/11 01:01
|
Joined: Dec 2008
Posts: 1,660 North America
Redeemer
Serious User
|
Serious User
Joined: Dec 2008
Posts: 1,660
North America
|
"Slow" and "fast" are relative terms. Neither of them will cause instructions to take a noticeable amount of time to execute, as long as they're not used excessively. So while you wouldn't want to be performing 500 long box traces each cycle, 50 short ones would be just fine. (I haven't stress tested that function so I don't know what the hard limits are, but basically use the "slow" functions sparingly and you'll be fine)
As for your question: c_scan() will only detect entities, not level geometry, so I wouldn't suggest you use that (unless your levels are made out of models). I would suggest you use a c_trace instruction in combination with the USE_BOX flag to perform a box trace upwards. That will accurately detect all surfaces above the "head" of your entity.
Last edited by Redeemer; 09/24/11 01:03.
|
|
|
Re: Bumping Your Head Physics
[Re: Valdsator]
#383705
09/24/11 08:16
09/24/11 08:16
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
User
|
User
Joined: Oct 2008
Posts: 513
|
To avoid this make sure you use c_move() for the movement and include a check for getting stuck by a collision in the while() condition. It would look something like this:
target_z = my.z + jump_height;
result = 1;
//MOVEMENT UPWARDS TILL YOU HIT THE CEILING
while((my.z < target_z) && (result>0))
{
result = c_move(me,vector(0,0,(jump_speed*time_step)),nullvector,IGNORE_PASSABLE|GLIDE);
}
A note on c_move from the manuall to clarify what "result" is being used for: The c_move function returns the amount of distance covered. If the entity could not move at all due to being blocked by obstacles, it returns a negative value or 0. Hope this helps. If you need a more detailed explanation head on to the other thread you created regarding jump height and time_step. You might have missed it, but while answering your previous question yesterday I thought this "floating" might be your next problem with jumps, so i adressed both problems in that thread with a more extense step-by-step explanation: http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=381979&page=2
|
|
|
Re: Bumping Your Head Physics
[Re: Superku]
#383716
09/24/11 12:02
09/24/11 12:02
|
Joined: Mar 2009
Posts: 186
Valdsator
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 186
|
c_move(...) if(HIT_TARGET && target.z > my.z+my.max_z*0.75) //you may not need the factor *0.75 { my.speed_z = minv(my.speed_z,0); } This works well, but whenever less than half of the player entity hits the ceiling, he continues to stay floating, most likely because of the ellipsoid collision system being used when hitting blocks. @Carlos3DGS: Wow, I missed your reply on my previous thread. That actually makes a lot of sense! Currently my jump system doesn't work quite like that, but I think I'll try re-coding it. Thanks!
|
|
|
Re: Bumping Your Head Physics
[Re: Valdsator]
#383723
09/24/11 14:14
09/24/11 14:14
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
There is a problem with Carlos3DGS' solution, you have no actual jumping curve and thus the jump will feel unnatural and not smooth. Additionally, when the ceiling's surface is not orthogonal to the z-axis, your player will probably slide along the ceiling because of the GLIDE option and it's upwards movement won't be stopped (because then result > 0). This works well, but whenever less than half of the player entity hits the ceiling, he continues to stay floating, most likely because of the ellipsoid collision system being used when hitting blocks. Then either remove my.max_z or decrease the factor.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Bumping Your Head Physics
[Re: Superku]
#383727
09/24/11 15:55
09/24/11 15:55
|
Joined: Mar 2009
Posts: 186
Valdsator
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 186
|
There is a problem with Carlos3DGS' solution, you have no actual jumping curve and thus the jump will feel unnatural and not smooth. Additionally, when the ceiling's surface is not orthogonal to the z-axis, your player will probably slide along the ceiling because of the GLIDE option and it's upwards movement won't be stopped (because then result > 0). This works well, but whenever less than half of the player entity hits the ceiling, he continues to stay floating, most likely because of the ellipsoid collision system being used when hitting blocks. Then either remove my.max_z or decrease the factor. Huh, you make a good point. The curve is very important. I solved my previous problem with your code. Because of how my collision box is set, I simply had to use min_z rather than max_z. Now it works perfectly! Thanks.
|
|
|
Re: Bumping Your Head Physics
[Re: Superku]
#384305
10/01/11 21:32
10/01/11 21:32
|
Joined: Mar 2009
Posts: 186
Valdsator
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 186
|
c_move(...) if(HIT_TARGET && target.z > my.z+my.max_z*0.75) //you may not need the factor *0.75 I'm wondering, could this also be used to check if the player is on the ground? How would the code look? I've played around with it, but I can't seem to get it to work.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|