Inside3D!
     

func_pushable going in wrong direction
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
catalyst



Joined: 17 Feb 2009
Posts: 26

PostPosted: Sat Apr 25, 2009 9:24 pm    Post subject: Reply with quote

hi guys,

had to contribute the last two months to my private, shitty life but am back working on the mod. big thx for all your advice! you didn't waste your time!

i changed to walkmove but a strange thing is happening in the map where i test the changes. sometimes, when i push the object, i hear the water splash sound. it happens only in one particular area (not a spot, an area!).

also, when i jump onto the object it makes me slide on it till i fall - ie no standing in one place like when i'm on the ground. yes, i know - it's because i'm not ONGROUND, but how could i be?
Back to top
View user's profile Send private message
Wazat



Joined: 15 Oct 2004
Posts: 732
Location: Middle 'o the desert, USA

PostPosted: Sun Apr 26, 2009 1:56 pm    Post subject: Reply with quote

The splashing sound plays automatically when an entity (I think solid entities that are not SOLID_BSP) enters water. Perhaps a corner of the object's bounding box is touching water or something. Depends on the area I guess.

The sliding off thing will happen with nearly all entities. If you turn on notarget so enemies cannot see you, then hop on a dog or grunt's head, you'll be unable to control the player's movement direction and slide right off.

The reason for this is you need to be ONGROUND in order to control the player's movement, have friction on the player's feet, etc. However, onground is only assigned when you stand on a SOLID_BSP surface such as the bsp world, a platform, elevator, etc.

There are two ways to fix this, then. The first is to make the object SOLID_BSP, but that doesn't work for what you're doing I'm guesssing. The second option is to manually apply FL_ONGROUND to the player in either a touch or think function. Either the block should test in its touch function whether the player is above it (give or take 4 units), or the player's prethink function (which happens before physics are run) should be running tracelines down from the player's center & corners to determine if there's something below him he wants to be able to walk on (like a func_pushable or a monster's head).

The player thinking method has its advantages (it can handle monsters as well as pushables). However, that's extra tracelines per player every frame or so. That is wasteful unless you intend to do more with it than the occasional func_pushable.

Putting a check in the func_pushable makes sure the tests are only done when the player touches it, and probably won't require any tracelines. The other major advantage is that the func_pushable needs to do this anyway -- after all, you don't want the player to be able to push the block just by standing on the top.... Unless you want him using it as a personal scooter, but that's a different matter entirely. Very Happy

I hope that helps!
_________________
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Back to top
View user's profile Send private message MSN Messenger
catalyst



Joined: 17 Feb 2009
Posts: 26

PostPosted: Sun Apr 26, 2009 9:45 pm    Post subject: Reply with quote

Wazat wrote:
The splashing sound plays automatically when an entity (I think solid entities that are not SOLID_BSP) enters water. Perhaps a corner of the object's bounding box is touching water or something. Depends on the area I guess.

There's no water in the map at all :/


Wazat wrote:

...manually apply FL_ONGROUND to the player in either a touch or think function...


I've put a condition on the walkmove function so that its called only if the player touching the func_pushable has the FL_ONGROUND so that he doesnt move the pushable when standing on it:
Code:
if(self.enemy.flags & FL_ONGROUND) {
   walkmove(self.enemy.v_angle_y, dist);
   }


If I make the pushable's touch function or the player's prethink function switch back the FL_ONGROUND flag on, the player will move the pushable when standing on top of it.
Back to top
View user's profile Send private message
Wazat



Joined: 15 Oct 2004
Posts: 732
Location: Middle 'o the desert, USA

PostPosted: Mon Apr 27, 2009 5:50 am    Post subject: Reply with quote

I don't know what to say about the water then. Although teleporters are technically liquid, so that's something else to look for. Or some other weird bug is happening in the map or code somewhere. What map, btw?

Regarding the onground issue, the best way to test if the player is above the block is:

if (player.origin + player.mins_z - 4 > block.origin + block.maxs_z)
{
// walkmove or whatever...
}

I include the - 4 to give it a bit of squish room. This way you can give the player FL_ONGROUND when he's above the block so he can walk, and only let him push it when he's not above it.

Do what you want.
_________________
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Back to top
View user's profile Send private message MSN Messenger
catalyst



Joined: 17 Feb 2009
Posts: 26

PostPosted: Mon Apr 27, 2009 9:35 am    Post subject: Reply with quote

I changed it a little bit. .origin i a vector, mins_z is a float, so I added _z to the .origin (it's now .origin_z). gonna try changing the FL_ONGROUND now.
Oh, and there should be a "below" sign <. the player needs to be below the pushable's top to execute walkmove.
Another fix: you can't add player's mins_z.

Code:
if (self.enemy.origin_z - 4 < self.origin_z + self.maxs_z) {
      walkmove(self.enemy.v_angle_y, dist);
   }


As for the water: it's my custom map. It must be "some other weird bug" indeed. I made a new map and put a new pushable inside and it seems fine now.
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Mon Apr 27, 2009 10:46 am    Post subject: Reply with quote

catalyst wrote:
the player needs to be below the pushable's top to execute

The player's *feet* need to be on top of the object. And steep slopes need to not count as ground.

if (self.absmin_z < other.absmax_z+1)
{
then(selfisstandingonother);
}
If other is solid_bsp then you need to do a trace to get the surface angle (trace_plane_normal_z < 0.7 then its too steep for onground). But this isn't useful on solid_bbox as they always have flat tops.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
catalyst



Joined: 17 Feb 2009
Posts: 26

PostPosted: Mon Apr 27, 2009 11:10 am    Post subject: Reply with quote

ok, i've got this code at the moment:

Code:
if (self.enemy.origin_z  - 4 < self.origin_z + self.maxs_z) {
      walkmove(self.enemy.v_angle_y, dist);
   }
   else {
      self.enemy.flags = self.enemy.flags + FL_ONGROUND;
   }


and it doesnt work. the game says "pushable_touch (NO FUNCTION)".
when i comment out the code after else. the pushing works fine (but i need the else code!).
Back to top
View user's profile Send private message
Lardarse



Joined: 05 Nov 2005
Posts: 243
Location: Bristol, UK

PostPosted: Mon Apr 27, 2009 11:12 am    Post subject: Reply with quote

Spike wrote:
trace_plane_normal_z < 0.7 then its too steep for onground

With arccos(0.7) being 45.57 degrees, that means that a 45 degree slope is not too steep, correct?
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Mon Apr 27, 2009 11:52 am    Post subject: Reply with quote

0.7 is the value quake uses, yes. You can stand on 45 degree slopes. Just not steeper ones.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Wazat



Joined: 15 Oct 2004
Posts: 732
Location: Middle 'o the desert, USA

PostPosted: Mon Apr 27, 2009 3:41 pm    Post subject: Reply with quote

Wazat wrote:

if (player.origin + player.mins_z - 4 > block.origin + block.maxs_z)
{
// walkmove or whatever...
}


Hrm, this would be better done as:
Code:

vector vec, selforg, otherorg;

if (other.absmin_z + 4 < self.absmax_z)
{
  // player pushes me

  // getting origins this way allows for BSP entities to work too, if you care about those.  Otherwise you can just use other.origin and self.origin instead.
  otherorg = 0.5*(other.absmin + other.absmax);
  selforg = 0.5*(self.absmin + self.absmax);

  // Don't move in the direction the player is facing.  Instead, always move away from the player.
  vec = normalize(selforg - otherorg); // dir from them toward me
  vec = vectoang(vec);
  walkmove(vec_y, dist);
}
else
{
  // Entity touching is on top of me.  If it's a player, let him walk on me.
  // To include monsters, this could be if(other.classname == "player" || other.flags & FL_MONSTER) {
  if(other.classname == "player") {
    other.flags = other.flags | FL_ONGROUND;
  }
}



Sorry I haven't tested this code. Not in a position to atm. Can someone look it over and make sure I'm not flubbing something?

It should do everything he wants. Instead of moving in the direction the player is facing, it always gets pushed away from the player (so if the player backs into it, it won't try to run into him).

If the player is above the block, it lets him walk on it. The -4 gives a buffer for the math, but 0.1 would probably suffice. The reason for -4 is so that if the player barely misses the edge I think he will step up onto it. I also check for the player classname just in case you're also allowing world objects etc to push this block (don't want to give them fl_onground).

If the player is not above the block, he will push it.

I hope that helps.


Edit: catalyst, your error is probably due to touching something non-player like the world.

Or it could be that you're using a + instead of a |. The vertical pipe in bitwise is the same as a + except it doesn't add the flag if it's already there. The plus doesn't understand bitwise operations, and adds the value anyway. This actually creates all kinds of weird effects because it adds other flags you didn't intend to add. It might have added FL_PARTIALGROUND or something and not liked it (I don't think any engines support FL_PARTIALGROUND).

Again, I hope that helps.
_________________
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Back to top
View user's profile Send private message MSN Messenger
catalyst



Joined: 17 Feb 2009
Posts: 26

PostPosted: Sun May 03, 2009 9:26 pm    Post subject: Reply with quote

vectoangles, not vectoang :)
but yeah! it does work now! just like it's supposed to!!! BIG THANKS!!!
Back to top
View user's profile Send private message
Wazat



Joined: 15 Oct 2004
Posts: 732
Location: Middle 'o the desert, USA

PostPosted: Sun May 03, 2009 9:41 pm    Post subject: Reply with quote

Glad to hear it! Very Happy
_________________
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group