New answers tagged

0

Thanks a lot everyone! I have been away the last couple of days which is why I haven't replied since then. The Mario example was interesting too. From my point of view, and for this project, it is also more important that the movement feels good rather than accurate. I've actually sort of figured this out using a different method. GameMaker has some ...


0

As I mentioned in my comment a terminal velocity is a result of drag on an object limiting the maximum velocity. This means that in order to have a smooth approach of the terminal velocity drag needs to be included somewhere in your game (of course this is not strictly physical as a small moon is unlikely to have an atmosphere to cause drag, I am going to ...


0

I'm unfamiliar with game-maker and its' syntax so I'll leave that part up to you. This psuedo-code should get you close: If (W) acceleration++; If (S) acceleration--; clamp(acceleration, min, max); velocity += normalizedDirection * acceleration * deltaTime; If (!landed) velocity += gravity * deltaTime; clamp(velocity, min, max); position += velocity * ...


0

Let's go through this: t = 0.0 dt = 0.0 currentTime = 0.0 accumulator = 0.0 Okay, som basic initialization, this is good. However, as Boreal mentioned, dt of 0 will cause problems. And since you are intending to fix your timestep, you should perhaps make dt a const and just set the value to whatever you want up here. Also, your currentTime initialization ...


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 ...


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

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 ...


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 ...


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.


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 ...


0

I'll use vector notation to be concise. You can translate this into individual vectorX and vectorY numbers if you're not using a vector math library, just be careful to calculate the length below using both components. // Get a vector pointing into the planet. Vector offset = planetPosition - playerPosition; // Note that x & y aren't separable: // you ...


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 ...


0

Every 2 objects that collide need to have at least 1 rigidbody between them. Both need some type of collider component, such as mesh, cube, cylinder


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 ...


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 ...


0

Then I'd suggest to play with velocity directly. It'd be easy to handle. I writing an untested code for doing the same but with velocity on Space Bar. Give it a try if this would help you. Rigidbody _rb; Vector3 _velocity = Vector3.zero; float _speed = 0.1f; void Start () { _rb = GetComponent<Rigidbody> (); } void Update () { _rb.velocity = ...


0

I'd just like to add, for completeness, that you could always try using a single collider for your GameObject, then infer what side it was on from the collision point. You can access the point like so: void OnCollisionEnter(Collision collision) { foreach(var contact in collision.contacts) { Vector3 pointOfImpact = contact.point; } }


0

Actually and hopefully you did attach all three colliders on same gameObject. What you have to do is create 3 children gameObject and attach one collider to one child. In that way you can detect what you want. Attach a Jon's script to each collider then in my OnCollisionEnter you can from which collider collision is occured through tag, any attribute or ...


0

You can always use OnColliderEnter (or OnCollisionEnter2D), and store the first collision. So consider something like this: Collider FirstCollider; int CollisionCount; void OnCollisionEnter(Collider collider) { if (FirstCollider == null) FirstCollider = collider; CollisionCount++; } void OnCollisionExit(Collider collider) { ...


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.


0

I guess you are using the initial world transformation of the body. you should get the current motionState transformation of the body to get the current position. Also make sure you are not stepping the dynamicworld or you will get the values after applying physics. I am usually using the below trick: Instead of using my_body->getWorldTransform(), try ...


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 ...


0

My answer is based on Lolums' answer. His logic is good, especially if you are making a simulation of something with realism. But Philipp points out something important as well: correct physics do not typically translate well to platform games. The take-away is that you should apply the idea of gravity velocity_y -= gravity * delta_time but you should not ...


0

Try changing the material of your box colliders. Also, I found a similar thread in Unity forums. That's about 2D, but the problem seems to be the same.


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 ...


0

Might not be useful but for a simple equation F=(mv^2)/r where f is the force, m is mass, v velocity and r radius. I'm not 100% sure but I think inertia is the force acting to slow down an object not speed it up.


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 ...


0

It you look at the Rigidbody or (Rigidbody2D) in the inspector under Constraints > Freeze Rotation you will see a checkbox for each applicable axis. These checkboxes will stop the physics engine from applying any rotation about that axis. Now that we have stopped the physics engine from managing the rotation we can control it ourselves by ...


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 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


0

Since you're not strictely looking for code-based answers you might want to try: Of course assuming it doesn't constrict your level design. (Skitskraj's answer is pretty good too tho)


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 ...


0

This is how I would do that (pseudo-code): class Vector { var float x; var float y; function Vector (float angle, float magnitude); // constructor function add(Vector); // adds new vector to current vector function angle(float new_angle); // returns or sets angle function magnitude(float ...


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 ...


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 ...


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

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 ...


0

It looks like you're using acceleration in a weird way in your engine, so I can't give you a 100% fool-proof answer you can directly implement into your code, but I can take a shot at it. You'd want to apply your friction to your current speed, not your characters acceleration. Try to change your code to this instead: if( curVel.x > 0.0f ) curVel.x ...


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 ...


6

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 ...


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 ...


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.


0

Stated that i agree with MickLH comments. Assuming no Air resistance. The flight time of a parabola thorw is : T=2*V0 * sin(a) / g where V0 is launch velocity , a is launch angle and g is gravitational acceleration. Th = V0 * sin(a) / g is the time from ground to higher point. In higher point your desired angle is 0 so compute (0 - angle) / Th ...


0

I finally found a solution, on this page: http://gamedevelopment.tutsplus.com/tutorials/how-to-create-a-custom-2d-physics-engine-the-basics-and-impulse-resolution--gamedev-6331 This completely elimenated both the sinking and the jitter.



Top 50 recent answers are included