Does anybody know how to use the LookAt using the Direction back instead of the forward? I want to pull something from the back and keep it looking toward the camera with the its back direction, but I don’t find a way to invert the LookAt method.
Thanks for your reply andeee!. That solution didn’t do anything diferent than LookAt itself. The object still using the forward direction to face the target. What I need to achieve is to face the target with the back of the object. Any other ideas?
Well I used your code but out of the method because I know the target and it will always the same, here is what I used:
----------------------------------
var offset = transform.position - myParent.transform.position; // my parent is the target to look at
transform.LookAt(transform.position + offset);
--------------------------------------------
This code doesn’t make the object to look backward to the target, it just make the object look at the target using the object’s forward direction.
What I need is: say you have a bullet going forward, then you want that bullet to return to you going backward, I don’t know if this is clear…
Bottom line is that I need to use the back instead of the forward direction when using LookAt.
There is not a place where to put the inverted transform as you advise, Unity assumes that the forward is the z axis and that is that.
I have a possible solution but it requieres to change all the code for the former forward movement of the arrow.
Here it is the solution I would have to apply in case that nobody know a cleaner or better way:
I will have to turn the arrow backward, then assume that the back of the arrow is the front so for example if I want to shoot the arrow I would say:
var myForward = transform.TrasnformDirection(Vector3.back);
trasnform.Translate(myForward * Time.deltaTime * someSpeed);
then when the time comes that I have to pull the arrow back, the forward direction of the arrow would be already facing the right direction. Now that is akward!!, to have to work with an inverted object the whole game code. :lol:
(note: there’s no fancy movement or anything in the included project’s scene, you can move the “Looker” in the inspector to see the LookAt/Rotate effect)
If the bundle is borked, you can hold alt while launching Unity and it will give you the option of opening another project.
ETA: I was also able to go into the directory with the project and delete from the Assets directory “LookAt.unity” and “Scripts/BackLookAt.js” and the Editor reopened fine.
The relevant script is as follows:
var lookAt : Transform
function Update () {
transform.LookAt(lookAt);
transform.Rotate(0,180,0);
}
Applying that to the child and setting the parent as the lookAt variable worked for me.
No problem man, it is just that I have unistalled my Unity3d and installed back, I have changed every folder name that could be pointing to the Unity3d.exe, but it keeps crashing! I can’t understand what happened. Let me try what you suggest now to see if I can open it. A pain!..
Thanks for your reply though, and I am sorry if I came back sort of harsh.
I finally could open Unity, I was missing the .js file that was inside the standard assets. Thanks for your help. Now I will try your code to see if it works for me.
Your code doesn’t work for me because then the arrow start moving backward when it should move forward and viceverse. Any other suggestions?
I can’t believe that more people haven’t find the need to do what I am trying to achieve…
" suppose you have a cannon that shoots a bullet with a rope in tied to its back, then after you shoot the bullet, the bullet land somewhere. Now if you want to pull that bullet back to the cannon using the rope and you want the bullet’s rear to lookat the cannon hole, that is what I have to achieve but in my case the bullet is just in space no ground.
Are you trying to implement some sort of “rewind” or “undo” functionality, or are you trying to actually wind some projectile back as though it’s on a string?
Yes the second one. A projectile on a string, so it has to be looking toward the string which is attached to the mouse of the cannon. Now you understand why the code you gave doesn’t work right?
So I thought that it was possible just to invert the lookat to lookat using the back direction with a simple “-” sign at front or something like that but I guess I am totaly wrong about that. I have read all the functions and commands in the documents and I didn’t find anything like it, but I could be missing something none the less so I decided to post the question here among the creme but nothing effective yet.
Perhaps it requires a complicate formula or math operation which I am not good with.
Maybe I misunderstand, but isn’t that what you’d expect? If you want the projectile to travel backwards, you’ll have to negate its movement on the z-axis in some way. If you want to be able to travel forwards towards something while pointing the visual rear of the object towards your target, what I’d suggest is that when the projectile ends its forward motion, replace it with another prefab that has its z-axis turned around and transfer the string’s transform to a script on the new object that does what you want (look at and move towards the string).
Yes I have the code wrong in the post, but I checked the my code and it is on the right order, probably since I was trying everything I post the one that had the code in that order.
Now last night I figure out a way to do it, and I am going to post the solution I found today for everyone who get tangle in the same situation can have a solution to start with. And of course if there is a better way to do it I would love to know it!