# Rotating source vector to destination vector (2D)

## Recommended Posts

I am trying to rotate a vector to a goal vector.
My main problem now is that I can't wrap my head on is which way to rotate the vector, so finding the "shortest" way to rotate (clockwise or counter clockwise).

##### Share on other sites

The dot product of the target vector and the normal of the current vector should result in a positive or negative value.  This result will determine whether a counter–clockwise or clockwise rotation should be made.

See attached.

Current direction vector A and its normal, A'
And sample target directions B and C:

##### Share on other sites

Edit, its 2d, what I wrote was 3d.

Edited by ErnieDingo

##### Share on other sites

If you use complex numbers to represent points and vectors, so you think of (x,y) as the number x+y*i, you can think of rotations as unit-length complex numbers, like cos(alpha)+sin(alpha)*i. Applying a rotation is now just complex-number multiplication. In that language, the rotation that maps a current vector to a target vector is simply z = target / current.

This might not be very satisfying because there is no notion of "shortest". The way mathematicians think of rotations, they are not things that happen progressively over time or anything like that, but just mappings that take an input vector and produce an output vector.

If you want to recover a notion of "shortest", perhaps you are interested in limiting how much the current vector can change in one step. This code would do that:

Complex limited_rotation(Complex current, Complex target, Complex max_rotation) {
Complex z = target / current;
// You may want to normalize z here if you can't guarantee that current and target have the same length
if (z.real() > max_rotation.real())
return z;
if (z.imag() > 0)
return max_rotation;
return conj(max_rotation);
}

Edited by alvaro

## Create an account

Register a new account

• ### Similar Content

• Hey all,

So I have this unfathomable obsession with the games LIMBO and INSIDE, two games produced by Playdead Studios. But as a sound designer, I'm specifically into the audio of the game, its use of ambient tracks and specific sounds to create this level of emotion I've never felt in a platformer before.

I took a stab at redesigning the sound and ambiance of one of LIMBO's trailers to see if I could replicate such emotionality with my own creativity. Check it out below. All feedback is appreciated.
Thanks!

• Been a bit quiet recently, but we've been busy bug fixing and tweaking things... Now we have lots more 'Particle effects' in the game, specifically here the Flamethrower and Enemy attacks!

• Hi and thanks for reading, I have an issue with this reactive crosshair script, everything works fine until I start changing the offset. Give the script a go and you will see what I mean, when I do SetOffset(0f); it doesnt always set back to the origional state, if anyone can spot a fix I'd be super appreciative!
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ReactiveCrosshair : MonoBehaviour { [SerializeField] GameObject c_limb_prefab; private float center_offset = 0f; private float current_offset = 0f; private float max_offset = .5f; private int number_of_limbs = 4; private float limb_length = .05f; private float limb_width = .005f; private List<GameObject> c_limbs = new List<GameObject>(); public void SetupCrosshair(){ for (int i = 0; i < number_of_limbs; i++) { GameObject line_go = (GameObject)Instantiate (c_limb_prefab); line_go.transform.SetParent (this.transform); Vector3 limb_pos = new Vector3 (0f,0f,0f); //line_go.transform.position = limb_pos; line_go.transform.localPosition = limb_pos; LineRenderer line = line_go.GetComponent<LineRenderer>(); line.startWidth = limb_width; line.positionCount = 2; line.SetPosition (0, line_go.transform.localPosition + new Vector3(center_offset, 0f, 0f)); line.SetPosition (1, line_go.transform.localPosition + new Vector3(center_offset + limb_length, 0f, 0f)); line.useWorldSpace = false; c_limbs.Add(line_go.gameObject); } if (c_limbs != null) { OrientLimbs (); SetOffset (0f); } } public void OrientLimbs(){ for (int i = 0; i < c_limbs.Count; i++) { float rotation_step = 360f / (float)c_limbs.Count; c_limbs [i].transform.RotateAround (c_limbs[i].transform.position, c_limbs[i].transform.forward, 90f + (rotation_step * (float)i)); } } public void SetOffset(float _current_spread){ float offset = Mathf.Lerp (0f, max_offset, _current_spread); for (int i = 0; i < number_of_limbs; i++) { if (offset > current_offset) { Vector3 pos = c_limbs [i].transform.position + (c_limbs [i].transform.TransformDirection (Vector3.right) * offset); c_limbs [i].transform.position = pos; } if (offset < current_offset) { Vector3 pos = c_limbs [i].transform.position - (c_limbs [i].transform.TransformDirection (Vector3.right) * offset); c_limbs [i].transform.position = pos; } } Debug.Log ("SetOffset() offset: " + offset.ToString () + " _current_spread: " + _current_spread.ToString() + " localPos: " + c_limbs[1].transform.localPosition); current_offset = offset; } }
• By nilkun
Hello everyone!
First time posting in the forum.
I've just completed my first game ever ( C++ / SDL ), and I am feeling utterly proud. It is a small game resembling Missile Command. The code is a mess, but it is my mess! In the process of making the game, I developed my own little game engine.
My question is, where would be a good place to spread the news to at least get some people to try the game?
• By Paul Bto
State of the search
I'm not looking / I'm still looking

Description
It is a third person game where you join more players to fight against bosses in the PvE style of the mmorpg, looking for online companions to help you defeat your enemy, where everyone does their respective work, such as tank, dps or heal, in groups of 5 or 10 players.
The difference with other mmorpg is that here, since there is no open world, you will not have to go through it doing hundreds of missions and using many hours to get to the content that really interests you, which, in the case of PvE, are the dungeons and raids.

Objectives of the project
For this project we will first make a demo that will only be the boss of a 5 player dungeon.
The first phase of this project is to release a video gameplay for crowdfunding (kickstarter maybe), so we will focus more on the visual, which could be falsified if the mechanics do not work. If the crowdfunding gives green light would be the game, which if in turn would work would be updated in the future with more dungeons and bands. The ideal would be to make a playable demo.

Compensation
If this game generates benefits outside crowdfunding, the profits will be distributed depending on the work and disbursement of each one.

Technology
Unreal. If you want to learn how to use this software with the project, you can.

Required profiles
- At the moment 2 Programmers (if has multiplayer knowledge in Unreal better).

- 1 2D Artist to make the interface design and some concepts. You are going to try make interfaces like this:

It would be ideal if you can devote at least 7 hours by week.
It is a plus if you have experience with high level PvE content in some mmorpg.

Team structure
Pablo. Environment artist.
Diego. Character artist.

Web
Waiting until the equipment is assembled.

Contact
pablo.barreto.jimenez@gmail.com

I have the GDD, it depends on the work but, I think the demo could be done in 6 months.
Here I leave some images of what I did of the project in Unity, where basically I have been testing (The project will be done in Unreal):

Desired feedback
If you think you can give me some advice about the project, feel free to give your opinion.

• By owenjr
Hi, I'm a Multimedia Engineering student. I am about to finish my dergree and I'm already thinking about what topic to cover in my final college project.
I'm interested in the procedural animation with c++ and OpenGL of creatures, something like a spider for example. Can someone tell me what are the issues I should investigate to carry it out? I understand that it has some dependence on artificial intelligence but I do not know to what extent. Can someone help me to find information about it? Thank you very much.

Examples:
- Procedural multi-legged walking animation
- Procedural Locomotion of Multi-Legged Characters in Dynamic Environments

• Hi guys, I'm having a problem rendering with DWrite, and I don't understand why, can you help me figure it out?
As you can see in the image below, if you look carefully you'll notice that the top of R8 is cut (missing 1 row of pixels), the bottom of R11 is cut again, the 4 in R14 is rendered weird compared to the 4 in R4 and so on, if you look closely you'll spot more yourself.
I can't figure out why 😕
Under the image I'll also leave the code, in case I'm doing something wrong like with type conversion or stuff. Any help is much appreciated

• Hello,
In the hopes that my thread is not off-topic or offensive in any way, I dare to ask the following "noob" question:
what would be the correct way to create sprite animations from 2D *.bmp files?
with the help of some tools i found , I was able to extract files containing what seems to be animation frames and frame shadow masks for animating a horse.
Attached are the archived assets.
My goal is to recreate the demo level of the game using Unity, for educational purposes.
I have started by loading the background map layer (also a large bmp file), and next step is to load a 2d character object and animate on the perspective.

Horse_Brown.rar
Hello guys, my name is Giorgi and i'm newbie game developer i'm learning Pixel art and after pixel art  i want learn C# and don't know how and where start i'm bad with programming language and know only HTML/CSS

• 18
• 11
• 16
• 9
• 49
• ### Forum Statistics

• Total Topics
631395
• Total Posts
2999780
×