Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

113 Neutral

About Tostaky42

  • Rank
  1. Hi,   I'm working on a 2d top down car game project. I'm on the physic part and I did the physics from scratch, with no middleware physics lib. From now I've calculated the lateral forces on front/rear wheels with the slip angle (the angle between the tire's heading and its direction of travel).   To find the slip angle: I do the sum of the sideslip (arctan between velocity.y and velocity.x) , the rotation angle (arctan between angular velocity ->yaw and the velocity.x) and  the steer angle.   And finally the traction / resistance force. It works pretty well, but i want to add handbrake on my car. And i don't see exactly how to implement it, I just want a feeling fun, not realistic. Anyone have some ideas ? Thank you :)
  2. Tostaky42

    Apply torque on angular acceleration

    Okay, thank you man. I fixed my problem. Now I have a physic engine who handle lateral forces and torques.
  3. Tostaky42

    Apply torque on angular acceleration

    Thank you for that clarification,  I understand better these notions :). im sorry but i have one more question. In my case I want to have like one button for accelerate the car, and the two arrows buttons to rotate my car left and right. The car will accelerate in the direction of the head of the car. Like in MicroMachine, or other top down car game. In this case do I need to store the orientation of the car and to apply it, each frames, to the traction force ? And how do i apply it to this traction force ? 
  4. Tostaky42

    Apply torque on angular acceleration

    Yes but the velocity vector is my direction vector here (its magnitude is the speed of the car). So i need to rotate it, no ? If I apply a force like Vector3(5000,0,0) it will go always on the direction of the right side of the screen, I want that this direction turn. I dont know if im enough clear, sorry for that ... 
  5. Tostaky42

    Apply torque on angular acceleration

    Okay, thank you for your advices, I found the problem, the rotation is good but its not applicated to the velocity vector. Its applied to the transform matrix of my object. How can i apply the rotation to the velocity vector ? Thank you in advance
  6. Tostaky42

    Apply torque on angular acceleration

    _inverseInertiaTensorWorld.transform(_torqueAccumulate) seems to work correctly. But the value of torque is null at this moment, and the interial tensor has good value. So I think the way to find torque is not the right way. What I want to do is to apply on the front side of the car to turn it left or right.  I do a vector product to find it. The orientation is not changing. I mean by this if I apply a force like Vector3(0,100,0), my object will still go up and the orientation will not change...    I change the matrix of the object each end of frame with the orientation and the position. 
  7. I'm working on a game project about a top down car game in 2d. I want to manage all the physics by myself. Im working with this book : http://www.amazon.fr/Game-Physics-Engine-Development-Commercial-Grade/dp/0123819768 to implement the physics. From now my physic engine can handle force on the different cardinal axes. But I have some issues to implement a correct simulation of rotation. Im trying to implement some torque to find angular acceleration. So I implemented an inertia tensor matrix : setMass(400.f); Matrix3 it; it.setBlockInertiaTensor(Vector3(2, 1, 1), 400); setInertiaTensor(it); void setBlockInertiaTensor(const Vector3 &halfSizes, float mass) { Vector3 squares = halfSizes.componentProduct(halfSizes); setInertiaTensorCoeffs(0.3f*mass*(squares.y + squares.z), 0.3f*mass*(squares.x + squares.z), 0.3f*mass*(squares.x + squares.y)); } To apply torque I apply a force on a body point of my car and I find the torque by a cross product : The meaning of this is to simulate the steering : player->addForceAtBodyPoint(Vector3(-2000, 1000, 0), Vector3(0, 100, 0)); void AObject::addForceAtBodyPoint(const Vector3 &force, const Vector3 &point) { Vector3 pt = getPointInWorldSpace(point); addForceAtPoint(force, pt); } void AObject::addForceAtPoint(const Vector3 &force, const Vector3 &point) { // Convert to coordinates relative to center of mass. Vector3 pt = point; pt -= _position; _forceAccumulate += force; _torqueAccumulate += pt % force; //std::cout << "torque x " << pt.x << " y " << pt.y << " z "<< pt.z << std::endl; } Vector3 Vector3::operator%(const Vector3 &vector) const { return Vector3(y*vector.z - z*vector.y, z*vector.x - x*vector.z, x*vector.y - y*vector.x); } The overload of modulo is the cross product   And finally I do the integration of all the physics data (forces and torques) void Player::integrate(float deltaTime) { addForce(_velocity * -150.0f); // Calculate linear acceleration from force inputs. _lastFrameAcceleration = _acceleration; _lastFrameAcceleration.addScaledVector(_forceAccumulate, _inverseMass); // Calculate angular acceleration from torque inputs. Vector3 angularAcceleration = _inverseInertiaTensorWorld.transform(_torqueAccumulate); // Update linear velocity from acceleration . _velocity.addScaledVector(_lastFrameAcceleration, deltaTime); // Update angular velocity from acceleration . _rotation.addScaledVector(angularAcceleration, deltaTime); // Impose drag. _velocity *= pow(_linearDamping, deltaTime); _rotation *= pow(_angularDamping, deltaTime); // Update linear position. _position.addScaledVector(_velocity, deltaTime); _position.z = 0; // Update angular position _orientation.addScaledVector(_rotation, deltaTime); // Normalise the orientation, and update the matrice calculateWorldLocalData(); // Clear accumulators. clearAccumulator(); } And the orientation is not working at all. Im not that good with physics stuff, so I think that im misunderstanding the physic implementation of torque with inertia tensor...    Thank you for your help.    
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!