New answers tagged

0

Well, I generally use to ask this questions in interviews :) Although I don't know Swift but I can give you a general idea about to achieve this. You have to play with some trigonometry to get current direction vector according to your current angle. Here is the pseudo code. float speed = 0.01 void GameLoop() { // I don't know that how Vector2 works ...


2

You will need a forward vector which represent the forward direction of your ship, and the velocity of your ship. // Stuff that you need (or already have) vec3 shipForwardVector; // This is according to your game infrastructure // and ship model; make it a unit vector. mat4 worldSpaceRotationMat; // assuming ship!.transform is only ...


0

What you're referring to as spin is formally called angular momentum. Depending on the level of detail you want, it can get complicated fast; this Q/A on Simulating Torque and Angular Momentum might be a good starting point.


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


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


1

From you code I can't tell what the ownerv vector is so I can't tell you why it's giving you the wrong result. But to do it from scratch, according to Wikipedia's article on vector projection, you can do the following; Create a vector a that is the direction from o to v. Create a vector b that is the direction from o to n. Let d be the dot product of a ...


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


0

Generally, when using a vector2 to represent velocity, the length of the vector is the speed, while the coordinates represent the orientation (the direction of the speed). To extract the length of your velocity vector, use the .len() method of your vector: float speed = velocity.len(); This is described in the doc.


2

Sounds like you're looking for the vector magnitude, also called (depending on context) its length, Euclidean norm, or Pythagorean Theorem. ie. speed = sqrt(dot(velocity, velocity)); As Alexandre Vaillancourt points out, in libGDX the len() method does exactly this. Other environments will almost always have an equivalent (eg. in Unity it's .magnitude) ...



Top 50 recent answers are included