. . . Posted September 22, 2021 Share Posted September 22, 2021 (edited) hello, I need help because I have no idea what's going on and something I'm working on really needs to be able to change the player's physics/capsule size freely.. I'm trying to change my player's capsule ThePlayer.Physics:SetCapsule(.1, 1) and the problem is whenever I do I teleport to where the player first existed in the world. For example if you exit the server in a specific spot then rejoin and then you move somewhere else and change your capsule you are teleported back to the position you entered the world in and I have no idea what's going on and how to prevent this not only for players but for other mobs too (it seems to happen for anything which can move) because I need to be able to change all their physics freely for my thing to work .. It would really help if anybody knows how I can change the physics capsule freely without being teleported and tells me ! Edited September 22, 2021 by . . . Link to comment https://forums.kleientertainment.com/forums/topic/133859-solved-how-to-change-players-physics-capsule-size/ Share on other sites More sharing options...
Nelzanger Posted September 22, 2021 Share Posted September 22, 2021 (edited) I don't know how the physics works in the game but I can already tell you that you're in for a bad time. Physics can be tricky to manipulate, and is not managed the same way like you would do in a non-physic context. Spoiler Some quick physics notions if you are interested. I know this is not what you asked for, but I need to explain first how physics manipulation roughly works in most of game engines (I'm not physics expert) : Let's assume you have an entity with a "transform", which is an object to describe your entity's position, rotation and scale. If you want to "move" your object to the right, you will tell in the code that your entity has its position changed : // Code based on what you can use on the Unity game engine // Vector3 is an object to represent mathematical vectors in 3D ( v (x;y;z) ) and Vector3.right is a short cut getting the vector for the X axis // Time.deltaTime is the interval in seconds from the last frame to the current one. You need to use it to make changes smooth on screen myEntity.transform.position = myEntity.transform.position + (Vector3.right * Time.deltaTime); Now, let's apply a "rigidbody" on your entity, which is a physic component that will tell the engine your object will now obeys to the physic engine, with gravity, torque, etc. If you let the code above, your object will teleport because you are resetting its position, and you are bypassing its simulated behavior. When manipulating physics objects, you will need to use the methods from the physics engine on your object by using forces because your object is now simulated by the physics engine, that will compute how you object moves, falls, rotates, etc. Manipulating directly a position on a physic object will always teleport it, because you are setting a fixed position to it. Moving your physic object on the right would loosely look like this : float thrust = 20.0f; //Apply a force to the rigidbody in direction of this GameObjects right axis myEntity.Rigidbody.AddForce(myEntity.transform.right * thrust); In your case, if a player has physics on it, it means he also has a collision, that will prevent it from falling through the ground. I don't know how it looks but usually, it's either a bounding box or a capsule. If you edit the capsule size at the runtime, two things can happen that I think are linked to your issue : The scaling is relative to a pivot point set to a player's feet. Scaling it at runtime might cause collisions issues, where your box goes temporarily under, or overlaps, the ground. Often in that case, the character falls under the map until a new collision is found. I suppose in DST that a security is set and your player is teleported back to the last saved position ; You are scaling to a value that is too small : if the collider is too small, the collision test can fail because at the instant t, your collider is above the ground, but at t + nextFrame, it went under due to it small size and therefore, no collisions has been detected. That's why high speed and physics is hard to implement (and why Sonic games uses tricks to make you "feel the speed", instead of making Sonic physically running at really high speed). Same case as above : a security is triggered and the player is teleported back to the last saved position. You will need to test what works and what doesn't, and probably check mods with physics in them so you can learn more on how the physics works or is used. I think you should try to set your capsule at 0.5 for both values and especially try to teleport the player a bit above the ground after a resize, so you make sure that he's above the ground (and not falling inside) for the collision when falling on the floor to work (Lots of games does that). Edited September 22, 2021 by Nelzanger 1 Link to comment https://forums.kleientertainment.com/forums/topic/133859-solved-how-to-change-players-physics-capsule-size/#findComment-1497426 Share on other sites More sharing options...
. . . Posted September 22, 2021 Author Share Posted September 22, 2021 I tested so much stuff and I finally found out how to fix it so it seems when you want to change the capsule you also need to use a code like this right after to prevent the teleport glitch inst.Physics:Teleport(inst.Transform:GetWorldPosition()) Thanks so much for your detailed post it helped me mess around more till I tried this ! 1 Link to comment https://forums.kleientertainment.com/forums/topic/133859-solved-how-to-change-players-physics-capsule-size/#findComment-1497459 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now