Hot answers tagged

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


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

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


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

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

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


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


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

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


2

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


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


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


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


1

you can just convert the coodinates. to do this, you have to use the normalized â as an base vector for the new coodinating system then use the 90º rotated norm(a.y,-a.x) as another base. lets name they as e1 and e2. now you can express your vector b as an linear combination of e1 and e2 with the linear system of equations: b = m*e1+n*e2 b.x = ...


1

Use rigidbody.AddForce instead of transform.Translate so that the collisions are detected. For the direction create a variable with the difference between the target and the object itself and then normalize to find out the direction.


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