Hot answers tagged

17

Always assume the client is a lying, cheating, bastard. The client is responsible for: Receiving input from the player (and sending commands to the server, which validates) Rendering the known gamestate The client is in no way allowed to calculate the gamestate except as client-side interpolation for smooth animations.


7

I suspected OP already knew this approach so I mentioned it in a comment as just a starting point, but I'll try fleshing it out a bit more... Most physics engines divide dynamic objects into two groups, "awake," and "sleeping." Objects sleep when they sit at rest, and wake when moved or accelerated by some outside influence. A sleeping object behaves like ...


5

So the first thing I noticed was that when you do previousTouch = currentTouch; currentTouch.Clear(); this should also clear previous touch since List is a reference type. The second thing is that there is no space partitioning so your collision check currently runs in O(n^2) as best case runtime. The third thing is that it's weird that you calculate ...


4

Kerbal certainly didn't go for the realism you're seeking. For a game, it's much easier to just fake it. While the ships designed in Kerbal are configurable, the parts are predefined in a very detailed way. Just look at what goes into making a part. That's a pretty big hint. All the parts have their drag defined. So, it's really just a matter of summing up ...


4

More than likely, it works like this (major speculations): Client sends Shoot command to server, along with parameters such as position, direction, velocity, type, etc... Server accepts command and broadcasts to all players on next frame. Clients render the shot. If shot hits a player, server broadcasts kill. Can't tell for sure though, as I don't ...


4

Note that most of us cannot answers specific questions about either of the games you mentioned. We aren't the authors of that code and can't reasonably know exactly how it was built. Generally speaking, there are multiple approaches. One approach is that the server is authoritative on everything. When a client wants to fire a weapon a round-trip to the ...


3

Have you considered playing the sound when the direction of the ball changes? Or like add that as a condition, in addition to the already "collide with object" condition.


3

Store the components and compute the matrix on-demand when you need it. Storing the matrix itself is inferior if you're ever going to be manipulating the transformation in any interesting or useful way, because floating point error can creep into the matrix after repeated successive mutations (such as rotations). This can result in a matrix that doesn't do ...


2

Summary My recommendation is to compute a restorative torque to apply to the object. This is physically more accurate than setting the velocity directly, and the simulation will be better behaved. This solution should also work for any launch angle. Below is a gif of this method at work stabilizing arrows launched from a car. Restorative Torque This ...


2

This problem is a bit difficult to think about because it's unphysical -- engines have a thrust which equates to acceleration and not top speed. So I think to fully answer this question, you need to remove it from a physical framework and just think of it in terms of vectors. To be clear, I will use "speed" whenever I am talking about the overall quantity ...


2

Interesting Question! Let me try to answer some of your points: 1 - How do I simulate physics on the server, do I need to rewrite parts of client side on the server side using a JavaScript physics engine? Yes, essentially, thats what you would do, if you want physics on the server. You have to ask you the question: Do I need the server to validate ...


2

To be physical, you need to calculate friction based on the magnitude of your velocity. You can simply remove the if checks when calculating friction and store a "friction constant" instead of a "friction force." You are already essentially doing this because m_fFriction is a double and not a vector, you are just thinking about it wrong. The friction ...


2

If I understand the problem correctly, you were close to properly solving it. Your approach with the normals is what you want, but instead of only saving the normal of the last collision, save a list of normals from all current collisions/overlappings. Then, play the sound whenever the new normal of the new collision is not yet present in the list. In ...


2

So far i have figured out, that it might has to do with the center of mass and the moment of inertia. You're right, it does have to do with the center of mass and the inertia. The resultant force is simply, the original force plus the force applied. The resultant torque is equal to the original torque plus the cross product of the force vector with ...


2

Physics student here. Firstly, separate your velocity into two components. Character { float velocity_x; float velocity_y; } Now, when they jump, you add an initial velocity to their velocity_y and every frame, you do something like loc.x += velocity_x * delta_time (and the same for y). Every frame, you also do velocity_y -= gravity * delta_time ...


2

The stock KSP model is known to be quite poor, especially in versions prior to 1.0. In 1.0, they replaced it with a semi-accurate model, where essentially the effectiveness of various parts varied depending on the speed. The best Aerospace model for KSP is a mod known as Ferram Aerospace Research, which has a very detailed description on their page. What ...


2

One thing a lot of people say here and is pretty fangerous is to have the player send information about his state when he shoots. The server is a machine, he can't decide who cheats and who doesn't. "Yes, I really did stand in front of him for 30 seconds without he noticing it, then I shot him in his eye while he was running around in a thight place, looking ...


1

You should use projectiles only for comparatively slow "bullets" like grenades from a grenade launcher or RPGs. For very fast bullets like bullets fired from a gun, A ray cast (or a ray-world intersection test) is used instead. A ray is fired from the barrel of the gun (origin of the ray) in the direction the character is aiming (direction of the ray). If ...


1

I found myself that to speed up my nbody. Instead of iterating through all of i & j. With i=0, i++, j=0, j++ and setting the force of object i to fG. I can use i=0, i++, j=i+1, j++ and set the force of object i to fG and object j to -fG.


1

It is recommended to move through Rigidbody so that you can achieve natural behavior. To do so, you can follow the following simple steps and write the following code in the script attached to your character. // Class level variable Rigidbody2D _rb; void Start() { // Assigning rigidbody2d component to variable _rb = ...


1

Dont use transform.Translate. it completely ignores collision. Try using rigidbody instead. It will make the movement smoother too


1

The answer is in your second sentence. Camera is child object of Character. The Camera should not be a child of the character. This is what is causing the camera to tilt. A child will follow its parent's transform. Remove the Camera from the Character. The script @Jon linked to will do what you want by modifying the camera transform, as the ...


1

Ok, I'm piggy-backing on Skitskraj's answer here so if you like mine, upvote his/hers too. Solution: Play the sound only if there is a new contact and there is a significant velocity change. I would suggest using the postSolve callback on the first iteration of the collision to determine if the impulse is above some threshold value required to generate the ...


1

I am no game designer or have any qualification but I have an idea for a realistic tactical semi turn based ship to ship combat system. Ideally it would be full 3d movement but it is likely easier to explain in 2d. So you would have the area of space between the 2 ships. This is measured in light seconds. Therefore at the start lets say there is a 120 ...


1

In Unity, the inertia tensor is represented by a vector of the diagonal of the actual inertia tensor. That is to say, there are no off-diagonal elements in the inertia tensor. As Pieter mentioned, you need to think of the inertia tensor as the mass of the object. Once you do that, you can draw results from correspondence to linear equations. We all know that ...


1

It sounds like you want to implement your own physics instead of using what's built in. Fortunately, you don't have do any kind of parabolic calculation when jumping (unless you want to project the path of the character or something like that). Instead, you let physics run its course which will naturally create parabolic shapes. Here is some example code for ...


1

Your problem lies in the fact that you have no "resting" state for your bodies. Any physics system has an amount of energy, be that kinetic, thermal, and so on. In reality, solid object deform slightly, and tranform some kinetic energy into heat, though it is hardly measurable. It's also worth noting that in reality there is no such thing as a completely ...



Only top voted, non community-wiki answers of a minimum length are eligible