# Tag Info

10

First we get a vector from B to A, as in the following picture: Now we have a vector that tells us how to get exactly from B to A. In code it looks something along these lines: var BtoA = A - B; In the above image's case, the resulting vector is X:15 Y:-20. At this point we actually already know the direction, as it is included in the information of how ...

8

You can simply get the vector pointing in the right direction, then scale it by the distance you want and add that to the initial point. This will define a new end point for your line. //Get the direction of the line Vector3 direction = point_B - point_A; //Get a new point at your distance from point A Vector3 point_C = point_A + (direction.normalized * ...

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

5

You can check simple ahead/behind relationships using the dot product: Vector3 displacement = B.transform.position - A.transform.position; float dot = Vector3.Dot(displacement, A.transform.forward); If dot is greater than zero, then B is ahead of A along A's forward vector. (The arrow from A to B has a component in the same direction as A's forward) If ...

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

4

It looks like your trouble isn't in computing the direction - it's that your arrow asset was imported with an unusual orientation, so when you use methods like LookAt or LookRotation they give you the "right" result for a standard orientation, leaving your arrow visually pointing somewhere else. You tried to correct for this by adding angular offsets to the ...

4

Random direction relative to current direction: Assuming you already have an initial direction vector prepared, as per DMGregory's comment on the OP: Generate a random float that will represent the angle to change the direction by. Since the angle should be constrained to a 90 degree arc "forward" of the initial direction, we restrain the range of the ...

3

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

3

IF I understood your question correctly (it's a bit un-detailed and I recommend editing it with more information and the piece of the code that you tried but is not working), you can solve the problem with many solutions. A very simple one, in C#, is the following (consider that p0 is the starting point of your projectile and p1 is the end point, both in 3D ...

3

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

3

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; max=point; for(int i=0;i&...

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

3

The spatial audio should be relative to the camera. If you consider it, even in a 3D game, the audio is relative to the camera. Sounds that come from the right side of the screen are heard from the right speaker, and sounds that come from the left side of the screen are heard from the left speaker. It just happens that the avatar is looking in the same ...

3

The dot product between two unit vectors is: +1 when the vectors are pointing in the same direction 0 when the vectors are perpendicular -1 when the vectors are pointing in opposite directions So, we can get this value just by normalizing our two direction vectors and dotting them, and then massaging the output into the 0-1 range. In Unity-style syntax it ...

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

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

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

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

2

If you know the start and end points as well as the desired length, you can use Vector3.Lerp Vector3 midPoint = Vector3.Lerp(startVector, endVector, 0.5f); Debug.DrawLine(startVector, midPoint);

2

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

2

The velocity is the difference between the new position and the last position. velocity = newPos - oldPos The vector direction is the normalized velocity. direction = velocity.normalized Rigidbody should update velocity each frame, even if you are using MovePosition(), however, if you need to know what the velocity will be before the object is actually ...

2

A few issues come to mind as I read this: Your movement is on the surface of a sphere, so travel direction should be a tangent to this surface, not just a (to-from) normalized, as that would point into the sphere. You mention acceleration and movement, but nowhere "velocity" or "speed." Use standardized terms, to make your intentions and code clearer. I ...

1

I suggest do not bind the flipping procedure to the Input since it is directly relevant to the moving direction of the body (Input may not change the body's moving duration in some specific occasions). Do it by simply checking the velocity vector of the rigidBody2D. It can be simply done by 2 ways: -Either you can check in the moving object's Update() loop ...

1

This is almost a comment, but too long so i'll post as an answer. Hopefully it will help. There's a design flaw i think in your code : you solve on x then on y but in both cases you set both x and y... So when you solve on Y, you 'break' the solve on X you just made. I think you should split the collision detection and its resolution : (pseudo-code) ...

1

Without knowing exactly the tutorials or books you have read, here is what I can tell you. To be more precise in terms of physics definition: the vector direction is calculated as the difference between current position and last position. The vector velocity is equal that divided by the time elapsed when going from one position to the other. See: http://www....

1

It works via repeated Rotations, you begin mentally with the Vector {1,0,0} then you rotate it along the Y-Axis the length of the vector is just one so you can get the new coordinates simply by evaluating sin and cos (of the angle along the Y-Axis), as their pair represents points on a circle hence rotating but you are rotating in another direction than in ...

1

First let's look at how to convert an angle (the yaw-angle) into a vector in two-dimensional space: As you can see the y-value is the sine of the angle and the x-value is the cosine of the angle. direction.x = 1 * cosYaw; direction.y = 1 * sinYaw; Now what happens when we add a 3rd dimension and rotate all of that around the x-axis by a new angle (the ...

1

So I solved this in kind of simple way. As I had the pointing vector(which in my specific case was y, but it doesn't matter that much) and I found out that I can actually get another vector out here. So I made a vector plane of x and y vectors. Than I did x.cross(y) and obtained z vector. Than I made those vectors 4D by setting w to be 0. After that I ...

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