Announcement

Collapse
No announcement yet.

how to convert make floats only take 2 digits after coma ?

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

    how to convert make floats only take 2 digits after coma ?

    isntead of

    1.65342 , This 1.6500

    Is there ant mathematical way ?

    Purpose ,

    When you send a vector to the server

    " unreliable Server function (float floatx ,float floaty ,float floatz )

    And well , i should explain a lot more i guess hehe...

    #2
    Code:
    function float twoDecimalPlaces(float f){
      f *= 100;
      return int(f)/100; 
    }
    ex:

    Code:
    1.65342 * 100 = 165.342
    int(165.342) = 165
    165 /100 = 1.65


    See this thread if you dont want any trailing 0's for a HUD representation (thanks OP Tegleg)
    ~~~

    Lossless Vector Replication

    if you are trying to preserve a vector due to replication I would make your own vector struct

    Code:
    struct LosslessVector{
      float x;
      float y;
      float z;
      //same structure as a vector but its your own struct so it replicates losslessly
    };
    
    
    var LosslessVector myLossLessVector;
    As per UDN on Variable Replication of Vectors

    "If further precision or larger bounds are required then you will need to create your own struct with three floats in it or to simply send each component separately."

    ~~~

    I've actually utilized this kind of setup in my own game for lossless vector replication of small vector values where the decimal actually matters (think DrawScale3D)



    Rama

    PS: you cannot use vector v = losslessVector v2

    you must set each float manually, since the structs are not of same type

    Code:
    v.x = v2.x;
    v.y = v2.y;
    v.z = v2.z;

    Comment


      #3
      I don't wanna replicate it , just send it to server with the server function

      So then there i spawn projectile , but it seems like lag happends easily that way , i tried a lot of ways to spawn a projectile and that's the only one that Works any ideas ?

      Well thanks ! looks like you got replication mastered already!


      And it seems that when i replicate a vector or a rotator , the server , changes the values like ... in it's own...

      I kinda not understand what's going on the server machine , i don't even know if anims play there becuse if i do this .




      Simulated function GetSockRotAndLoc()
      {
      Mesh.GetSocketLocationandRot(BlahRot, BlahLoc) ... //pseudo..


      if(Role < Authority)
      {
      ServerGetSockRotAndLoc();
      }
      }


      Server Function ServerGetSockRotAndLoc()
      {
      GetSockRotAndLoc();


      }


      And , then the server , doesen't get the real values that happends on clients or maybe it's vice versa...

      Well but it logs on server , different values , if im for example on an animation that never ends from an animSlot , the server logs are like im not in that animation
      But anyways throgh clients i see that animation going on .. idk it's kinda weird ...

      So if i spawn , a projectile on pawns hand , it's going to spawn as the animation was the idle one and not the animslot one... " from server " when i call it on the server " .

      Well i don't know what you understand for replication , i understand for replication when a variable it's on the replication block else is not replication .. " i guess "

      Comment


        #4
        both vectors and rotators are optimized by unreal and this means data loss, rotators its less noticeable because rotator values are quite large usually, but with vectors use my code above

        ~~~

        Replicating Animations With Listen Server

        my setup for handling a listen server and a client is

        Code:
        var repnotify bool doAnimation;
        
        replication{
         if(bNetDirty)
          doAnimation;
        }
        
        simulated event ReplicatedEvent( name VarName )
        {
        	//very important line
        	super.ReplicatedEvent( VarName );
        	
        	if (varname == 'doAnimation') {
        		yourAnimation_REPNOTIFY();
        	}
        }
        
        simulated function yourAnimation_REPNOTIFY(){
           //actual animation code
        }
        
        //this is the actual function called by button presses or game events
        // this will play animation on the listen server as well as client
        reliable server function playAnimation(){
          
        
          //always change the value due to bNetDirty, the value must change
          //or repnotify will not fire
          //        this is simple boolean setup to cause repnotify to fire always  
          doAnimation = !doAnimation;
        
          //run code for server, repnotify events do not fire off for servers at all
          // so you must run the code yourself in your main function
          yourAnimation_REPNOTIFY();
        }
        
        
        //dont set these properties for utpawn, 
        //leave utpawn multiplayer properties alone :)
        
        //set these only if making your own classes
        defaultproperties
        {
                //Multiplayer
        	RemoteRole=ROLE_SimulatedProxy //so simulated functions work
        	bOnlyDirtyReplication 	= true
        	bAlwaysRelevant		= true
        
        	NetUpdateFrequency = 3 //(utpawn uses 100)
        }

        Might seem like some extra steps but as you'll see in my recent multiplayer videos this setup works great for me regarding listen servers (ty Solid Snake for the encouragement)

        Rama

        PS: note that you must run the main playAnimation() function on the server to fire off the repnotify events, that's why reliable server is used

        Comment

        Working...
        X