#[v1.1.0 Lab API] Custom Gravity

1 messages · Page 1 of 1 (latest)

jolly needle
short summit
jolly needle
#
  • In this week i will add class specific default gravity probably.
vague ibex
sly olive
grizzled leaf
#

sadly

#

nor ragdoll too

jolly needle
# grizzled leaf this do not affect pickup

I was planning to add those this week, i just published it now because ,me being dumb i have created a .NET project instead of .NET Framework and tried to debug all my code. I felt so dumb at the end lol

#

And it was getting late for me. I published this because it is working rn for players really good

grizzled leaf
#

Also ragdoll would need client change

jolly needle
jolly needle
vague ibex
grizzled leaf
jolly needle
vague ibex
#

Yeah, but that's not gonna change the unity physics :3

jolly needle
#

We can actually, items like pickups are server authorized. And their positions gets synced with players.

#

If you change their server positions.

#

Vola

#

Currently adding very customizable item gravity vectors

white escarp
#

Does these actually work?

jolly needle
#

Plugin currently has the gravity modifier for players, but im currently developing the gravity modifier for items too

white escarp
#

I though it would move the item back and forth on client

jolly needle
#

it worked

white escarp
#

epic

jolly needle
#

there was floating medkits

#

really cool

white escarp
#

Might add that as a base labapi property too then

jolly needle
#
// Makes us able to Set a Pickups gravity easily.
public static void SetPickupGravity(Pickup pickup, Vector3 gravity)
{
    // Check if Rigidbody exists.
    if (pickup.GameObject.TryGetComponent<Rigidbody>(out Rigidbody rigidbody))
    {
        // Disable the default Rigidbody gravity so we can add our own one.
        // We are doing this because we dont want to change the whole games Gravity value.
        pickup.GameObject.GetComponent<Rigidbody>().useGravity = false;

        // Add a Constant Force component to simulate our own force
        pickup.GameObject.AddComponent<ConstantForce>().force = gravity;
    }
    
}
#

it just tried and gets the rigidbody

#

disables gravity

#

and adds a constant force component

white escarp
#

Ahhhhh

#

I see

jolly needle
white escarp
#

why do you get the component twice

jolly needle
#

oh thats right

#

my dumass

white escarp
#

silly

jolly needle
#

first i added the

#

getcomponent

#

and i thought

#

what if its null

#

and added the tryget

#

and forgor the getcomponent

white escarp
#

Very cool anyways

jolly needle
#

thanksie

#

Next i will figure out how i can modify ragdolls gravity

#

if its possible

white escarp
#

I dont think you will be able to do that

#

They are client sided

#

I mean their physics

jolly needle
#

yeah ragdolls are better client sided

#

imagine server authorizing every limb

#

im making every ragdoll client sided in my game too

white escarp
#

Ill add synced property then

#

they are going to be even more desynced on clients than before oh god

jolly needle
#

lolllll

#

i hate online game development but i love it at the same time

#
// Makes us able to remove the pickups force component and enable the default rigidbody gravity.
public static void RemovePickupGravity(Pickup pickup)
{
    // Check if Rigidbody exists.
    if (pickup.GameObject.TryGetComponent<Rigidbody>(out Rigidbody rigidbody))
    {
        // Enable the rigidbody gravity.
        rigidbody.useGravity = true;
        
        // Check if the Constant Force component exists.
        if (pickup.GameObject.TryGetComponent<ConstantForce>(out ConstantForce constantForce))
        {
            // Destroy the Constant Force component. Atomize it...
            GameObject.Destroy(constantForce);
        }
    }
}
#

and this is the function to remove it

#

in case*

white escarp
#

makes sense

jolly needle
#

just reverse

tardy basalt
#

Physics.Gravity or something like that

white escarp
#

Oh right I could just sync the default gravity lol

jolly needle
white escarp
#

We are having 0G gaming with this one

jolly needle
#

im using ChangedRole event for players and for some reason. For gravity to be applied i should delay the gravity set for 0.2 seconds

Timing.CallDelayed(0.2f, () =>
{
    ev.Player.Gravity = gravity;
});
white escarp
#

For some reason its being sent the next frame?

#

But you send the gravity message before

#

And it just gets discarded to not cause any exceptions

#

Ill look at this eventually

#

I think just moving the event should do the job

jolly needle
#

yeah there is ChangingRole event i know that it fires before the change of the role that why i used the ChangedRole but it still needed some magic to work

white escarp
#

Yeah in short ill fix it

jolly needle
#

It is working nearly flawlessly but one thing i noticed. Thrown items are lagging because of the server and client position difference. But when item hits something, it gets synced.

white escarp
#

Hm

#

Yea looks like ill have to sync them anyways

jolly needle
#

Yeahh, it is really interesting.

#

But it works and looking cool

jolly needle
#

I have released the version that you can control the pickups gravity.

sly olive
inner glacier
#

nvm I misread it as client side for some reason and was going to say that it's not

grizzled leaf
#

Lol

jolly needle
#

[v1.1.0 Lab API] Custom Gravity

#

I am currently thinking of setting gravity for spesific classes

#

but i dont know if it will be useful

sly olive
vague ibex
#

Yo! Just wanted to post that this plugin posts errors on the 14.1 release, but seems to function fine.

#
at LabApi.Events.EventManager.InvokeEvent[TEventArgs] (LabApi.Events.LabEventHandler`1[TEventArgs] eventHandler, TEventArgs args) [0x0001d] in <bea7f403b90e4786abd99fa819db9853>:0
unreal vigil
#

same here

jolly needle
#

Yeah changed event seems like is changed or its name changed. Itll be fixed today.

jolly needle
#

oh i completely forggor, will do it dont worry