Announcement

Collapse
No announcement yet.

Switching an emitter on/off when player enters/exits water or vehicle

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Switching an emitter on/off when player enters/exits water or vehicle

    Thanks to epic finally fixing their species code to work online, I've been able to create a funky emitter to attach to a custom player model. I've simply created a custom species, then use that to spawn and give an inventory item to my pawn. The inventory item then spawns an emitter and attaches it to a bone in the pawn. No problems, works like a charm.

    Now I've hit a problem. Two problems in fact:

    1: I'd like the emitter to die and be replaced by another, different, emitter when the player enters a water volume (to simulate bubbles underwater, instead of the effect I'm currently using). I've been playing around with PhysicsVolumeChange, but so far haven't been able to figure out a way to get the emitter to disable temporarily and be replaced by the second one.

    2: I don't really want the emitter staying active while the player is in a vehicle that draws the 3rd person mesh. This is also giving me a headache, as I can't think of a way to kill the emitter when the player enters a vehicle and restart it when they exit the vehicle.

    These are the 2 important classes (the emitter itself is just a basic emitter class with no extra code):

    Code:
    //Spawned by the SPECIES class
    class ChairInventoryAttach extends Inventory;
    
    var ChairEffect		ChairEmitter;
    var ChairWaterEffect	ChairWaterEmitter;
    
    simulated function PostBeginPlay()
    {
    	Super.PostBeginPlay();
    	CreateChairEmitter();
    }
    
    function CreateChairEmitter()
    {
    	ChairEmitter = Spawn( Class'ChairEffect', self,, Location, Rotation );
    	if ( ChairEmitter != None )
    	{
    		ChairEmitter.SetBase(Self);
    	}
    
    	log("EmitterAttached: "$ChairEmitter);
    }
    
    function SetupEffect(xPawn P)
    {
    	//attach the effect to the bone
    
    	P.AttachToBone( ChairEmitter, 'EMITTERBone');
    }
    
    function Destroyed()
    {
    	if( ChairEmitter != None )
    	ChairEmitter.destroy();
    
    	if( ChairWaterEmitter != None )
    	ChairWaterEmitter.destroy();
    
    	Super.Destroyed();
    }
    
    defaultproperties
    {
    }
    Code:
    //species class - player name changed to protect his identity ;)
    class SPECIES_Blah extends SPECIES_Human
    	abstract;
    
    static function bool Setup(xPawn P, xUtil.PlayerRecord rec)
    {
    	//Setup and attach the effect
    	Super.Setup( P, rec);
    	AttachEffect( P);
    	return true;
    }
    
    static function AttachEffect(xPawn P)
    {
    	local ChairInventoryAttach inv;
    
    	inv=P.Spawn( Class'ChairInventoryAttach');
    	inv.SetupEffect( P);
    	inv.GiveTo( P);
    }
    
    defaultproperties
    {
    	SpeciesName="Blah"
    	RaceNum=154
    }

    If anyone can give some pointers as to how I could achieve these two things, I'd be very much obliged :up:

    #2
    ok this will tell you if you're in a water volume:
    Code:
    simulated funciton Tick (float DeltaTime)
    {
    if (self.TouchingWaterVolume())
         log("I'm all wet");
    }

    I seem to remember their might be a non tick way to detect volume changes in the Pawn or xPawn Class, but I don't know what it is...


    For Vehicles you want to look at the
    function bool KDriverLeave(bool bForceLeave)
    function KDriverEnter(Pawn p)

    Comment


      #3
      event PhysicsVolumeChange( PhysicsVolume NewVolume )

      Also, theres nothing wrong with destroying the current emitter, and spawning a new one in its place.

      Comment


        #4
        Forewarning:

        Keep in mind that most emitters are set to bTearOff=true in their default properties. This is, if you are extending from an existing emitter class. This will make the server destory the emitter but clients will continue to exist.

        Ultimately, I am telling you:

        If you run across the problem of the server (or you being the listen server) successfully changing emitters but clients in a netgame still keep the old emitter (and also still gain the new one) it's because your emitter is set to bTearOff which means it's no longer associated with the server basically.

        A simple bTearOff=false will keep it in sync so when the server whacks one they all get hacked. You may even want to make sure it's role is RemoteRole=Simulated_Proxy.

        Just a little heads up incase that happens...

        Also, the aforementioned event is great for volume changes but you'll want to use the DrivingStatusChanged event for your vehicle inquiry.

        I would suggest adding a call to a function that you make within both the physicsvolumechange and drivingstatuschanged events. The function could possibly look to see what type of volume they are in (like the mentioned example above) and also, for vehicle purposes, check the bDriving boolean variable of the pawn to see if they are getting in, or out of the vehicle. (notice: I'm not sure about the altercation of bDriving if you are a passenger, however... anyone?)

        Comment


          #5
          There is a variable called DrivenVehicle that is a reference to the vehicle you are in, None if youre not in one. Thats probably a safer way to check for vechicles.

          Comment


            #6
            Double thanks bone. I can use that myself.

            Comment

            Working...
            X