Tag Info

Hot answers tagged

5

I suggest the following method: Build a vector pointing to the ship’s left, from its up vector and current direction. Build a similar “left” vector using the target location, as if the ship was already pointing in the correct direction. These two vectors lie in a 2D plane orthogonal to ship_up. You just want the angle between them. Using GLSL syntax, ...


4

You could always deploy a type of Linear Interpolation. This allows you to slowly move to the target rotation over time and make it look decent. If I'm misunderstanding and you simply want the angle between the two vectors, you might want to first normalize them (as you have done) and then simply take the dot product and angle. You can find a StackOverflow ...


3

i didn't read all of your code but if i get it right you want a curve movement. in linar algebra you can use vector addition for velocity and acceleration of object lets say : my_pos = (0,0) velocity = (1,3) acceleration = (0,-1) //gravity? do(lets say every half a second?) { to_move_x =velocity.x + acceleration.x to_move_y ...


3

You first have to figure out which direction is 'to the right' of your character. For thsi you will need to know which way the character is facing (uusally 'direction') and which way is up typically (0,1,0) or it could be the normal of the plane the character moves around on. right = Vector3.Cross(direction, up); Next, we need a vector representing the ...


2

You can use vector cross product for that. Create a vector from character to the clicked position and take a cross product of that and the character facing direction. The sign of the cross product "up" component determines which side was clicked. For ground plane this is the y-component of the cross product. For arbitrary plane, use dot product of the cross ...


2

What you have now is essentially: screenPosition.X -= velocity * 1.0; screenPosition.Y -= velocity * 0.0; You need to explicitly add a Direction variable which is a 2D vector (you are dealing with 2D, right?). Direction = (1.0, 0.0); You might be already seeing my lead. You need to scale Velocity by Direction and add to your Position like so: ...


2

While the equations v(n+1) = v(n) + a d(n+1) = d(n) + (v(n+1) + v(n)) / 2 with: d(n) is position at time n; v(n) is velocity at time n; and a is acceleration in distance units per frame per frame are arithmetically (and physically) correct, they are computationally problematic. The faster your frame rate becomes the larger the ...


2

Every frame: acceleration <-- from input velocity = velocity + acceleration * t position = position + velocity * t with t= time passed since last frame UPDATE: Reading again the question I thought you would need also the direction. I didn't specified because I assumed that acceleration, velocity and position are vectors. By the way if you ...


2

As hinted by user concept3d, it is difficult to help you without further details about your implementation approach. I'm going to give it a shot nevertheless, but that means that I have to make some assumptions that may or may not be true for your code. In any event, I hope that the following is general enough that you can adapt it if necessary. The first ...


2

I've already found some time and solution to my problems and I want share it with you. Maybe it will help someone: float distFromCentroid=ACamera.far(); camera.setLookAt(frustum_centroid+dir->direction*distFromCentroid,frustum_centroid); for(int i=0;i<8;i++){ point[i]=ACamera._point[i]*camera.matrix; } min=point[0]; max=point[0]; for(int ...


1

The white vector is the correct vector with the code you have. If you're only ever adding integers to your position, the movement is going to be at increments of 45 degrees. That's restricted to orthogonal and diagonal movement only. If you want free movement you should be normalizing the movement vector. Check to see if the libraries you're using have a ...


1

You just have to add acceleration to your speed. For every "frame" you have to do v = u+at where v is the new speed, u is the old one, a is the acceleration and t is the time http://en.wikipedia.org/wiki/Linear_motion#Acceleration


1

Finally I solved my issue as follows: update(double elapsed) { double targetAngle = Math.atan2(B.position.y - position.y, B.position.x - position.x); double currentAngle = orientation.toRadians(); //Calculate angular deviation double deviation = targetAngle - currentAngle; double absDeviation = (deviation < 0 ? -deviation : deviation); double ...


1

thank you for your answers. Linear interpolation sounds interesting, but I wasn't able to solve my problem with it. What I didn't mention in my question is that object B can change its position while A is aligning to it, so the adjustment of the interpolation scalar seemed quite difficult to me. (e.g. if the angle between both objects increases, the ...


1

The way I would do it would be to have my character object have it's own render method, and a member variable to hold direction data. You could make an enum to define the different possible states if you wanted to. Then within the render method, check what state the direction is in (possibly using a switch/case) and render the corresponding sprite. Wherever ...



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