Jump to content

Bizarre physics velocity bug that only happens when no ones watching


Recommended Posts

Ok, so I have a set of physics objects that move around screen and follow the player like hitboxes, but I've recently noticed some issues with some of the hitbox physics properties. Every tick, the hitbox's position is snapped to the player and it's velocity is supposed to update to match the player's current velocity as well. The player starts with a single hitbox that spawns as part of their initialization, and continue to follow them around. But for any hitbox spawned after that, attempting to change it's velocity "box.Physics:SetVel(x,y,z)" does nothing, yet it can still be moved around the map with "box.Transform:SetPosition( x,y,z )".

Strangely enough, it's not just "any hitbox after the first" that has this issue, it's any hitboxes spawned after the player has already spawned. If you put a single frame of delay on the creation of the first hitbox, the same issue happens.

So I loaded the mod onto a multiplayer world and joined with a second account and what did I discover? The first person to join the server had a normal functioning hitbox, but any player who joined after that had a frozen hitbox that couldn't change velocity. UNLESS both players joined at the exact same time, then both of their initial hitboxes work fine.

 

Basically, if anyone is online at the moment a physics object is created, that physics object's velocity can't be changed, if it's mass is 0. 

(well, it can also be fixed by changing the Physics:SetMass to 1 instead of 0, but that means overlapping hitboxes collide with each other and gravity also applies to them, so I don't want that)

 

It's kind of an obscure bug and I'm guessing this is something with the physics engine that we might not have access to. But just curious if anyone else actually works with physics objects out there and knows a solution to this.

Link to comment
Share on other sites

1 hour ago, CarlZalph said:

Have you tried issuing a .Physics:Teleport(x,y,z) and/or .Physics:SetMotorVel(0,0,0) before SetVel?

I've tried SetMotorVel as well and that has the same result, unfortunately.

I hadn't tried the physics version of teleport until just now, but that seems to work just fine, much like Transform:SetPosition() does.

Strangely enough, print logs show that the frozen physics boxes "think" they have a velocity that matches the players, despite them staying perfectly still.

Link to comment
Share on other sites

9 hours ago, pickleplayer said:

Strangely enough, print logs show that the frozen physics boxes "think" they have a velocity that matches the players, despite them staying perfectly still.

Hmm, I wonder if the physics thinking it's in the sleeping state.

There's the IsActive function that can check if it is or isn't, and SetActive to set it being in the sleep state or not.

Link to comment
Share on other sites

9 hours ago, penguin0616 said:

I don't know too much about how the physics work in the game, but does your issue lie anywhere else? Are you making sure you're setting it at the right time, keeping it updated, setting from the mastersim, etc?

There's always a chance I could be overlooking something, but I've spent quite a bit of time breaking down this issue into it's most basic components and trying different physics objects. It seems to me it boils down to this:

local master_postinit = function(inst)  --A player's master_postinit

	--This one works fine
	inst.components.hurtboxes:SpawnPlayerbox(0, 0.7, 0.35, 0.7, 0)

	inst:DoTaskInTime(0, function() 
		--This one doesn't
		inst.components.hurtboxes:SpawnPlayerbox(0, 0.7, 0.35, 0.7, 0)
	end)

It doesn't seem to matter what other factors are at play, as long as the physics object was spawned at least one tick after a player has, it's velocity can't be changed.

55 minutes ago, CarlZalph said:

Hmm, I wonder if the physics thinking it's in the sleeping state.

There's the IsActive function that can check if it is or isn't, and SetActive to set it being in the sleep state or not.

I had wondered this as well, but it shows that they are active. 

Link to comment
Share on other sites

2 hours ago, penguin0616 said:

@pickleplayer Would you mind sharing your code?

Oh boy, it's pretty huge. I replicated the issue and pasted it into an outdated esctemplate mod for you to look at instead. You can see the yellow circle that spawns when first loading into the world is given a velocity, and the second one that spawns isn't.

A few more fun things I found while testing these. The physics objects spawned on initialization also loses the ability to change velocity if:

  1. They don't have a physicsCollisionCallback function (even a blank one will fix it)
  2. During the first frame of existence; they are placed within 1 square unit of point 0,0,0 on the world map, and any player spawns close enough to see it on screen.  fun.
Link to comment
Share on other sites

4 hours ago, CarlZalph said:

Do a: .Physics:SetActive(false) + .Physics:SetActive(true) before the SetVel call and the thing moves.

Oh my god I can't believe I never thought to try that. I had to put it in a very specific spot and add a blank collisioncallback to get it to work but it works! Thank you guys so much.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...