Unity3d 5.6.0 How to transform the mesh - unity3d

First of all, I'm a german so please forgive me my (maybe bad) English.
I'm programming a 2.5d Puzzle Jump'n'Run like Trine and of course, you can play an archer/ranger/etc. And you shoot an arrow by clicking on the screen and the archer will rotate his upper body, his arms with the bow and the head so that the bow is looking at the Point where you clicked on the screen.
Here is the problem: How can I rotate or transform the mesh of my character, that he/she is looking at the point because when I just rotate the element by script, the animator sets the Rotation to the default Rotation changes of the Animation.
Is there any way to handle this or do you know of another method?

Related

Unity 2D: Alter sprite anchor point

I've got a plain 2D Capsule Sprite. I want it to rotate around a specific point instead of its very centre. In other programs, this point is called the anchor point. For context, I'm making a paddle for my 2D pinball game so obviously the paddle needs to move when you press a button, but I can't have it moving around its very centre... Well, I could but I don't want to.
So my questions are:
Is anchor point the correct term for Unity?
Can this be altered/moved and how?
So, I ended up getting an idea from a friend who does this stuff too.
I made an empty game object. Made it the parent of my paddle. Moved the paddle to the point of the game object where I want the paddle to rotate around, and now when I rotate the game object, it rotates the paddle around the pivot point that I want it to have.
Image of paddle, arrow pointing to the empty game object
Edit: Just works using UI components within a canvas
You can use the Anchor presets of the Rect Transform. Or define the Min/Max values for x/y coordinates in Anchors Property.

How do I make my square not flip over in unity?

I am learning to code and make games in unity, so I am very much a beginner. I made a little square jumping game in 2D that can jump, and move Left and Right. But for some reason the physics make it so that my square can flip over and it wont jump after it does. I have a GameObject that is named feetPos so that my square can jump, but as soon as the square flips over it wont jump again. is there any way to fix this? Or make my square not flip over?
(I don't know how to put link of the code)
Not exactly sure if this would help your specific issue. But to stop rotation of your square entirely once it jumps you could:
go to the Rigidbody2D Component for your square,
and then navigate to Constraints:
then selecting the 'Freeze Rotation' option for the z-axis of your square
you can find out more about RigidBody2D rotation on the unity manual docs for the different types of body types your Rigidbody2d component may use:

Make an object rotate according to mouse movement. [UNITY C#]

I’m starting a learning project. The idea is that you have an archer character that is static, that has a bow attached to it that shoots arrows to targets of varying difficulty.
Turns out that right at the start I’m stuck. How do I make it so that the bow rotates when the player clicks and holds the mouse anywhere on the screen? So I click+hold and move left/right and the bow rotates left/right to aim the shot. I’d like to also eventually make it portable to phones (so you’d tap+hold etc).
Stack Overflow isnt a code writing service but i will explain what you must do:
Method 1 (Exact Aiming):
For every frame the mouse is down:
Make a Ray from a screen point... hint (use
camera.ScreenPointToRay).
Get a far point along the Ray using ray.GetPoint(distance);.
Bow.Transform.LookAt(newPoint, Vector3.Up);.
Method 2 (Continuous Movement):
Make a variable oldMousePos to store a Vector2 location.
Record your initial screen click position into that variable on a
mouse down event.
Have a function that runs once every frame the mouse stays down.
For the direction of the rotation of the bow, you can use
(newMousePos - oldMousePos).normalized;.
For the speed of rotation for your bow, you can use (newMousePos -
oldMousePos).sqrMagnitude;.

How do I make my character's arms point towards the camera or cursor in Unity?

I'm making a fps game and I want my character's arms to rotate up and down depending where the cursor/camera is pointing at. The character already rotates when I turn left or right. Hopefully someone can answer my question. I'm new to Unity and I'm still learning how to code in C#.
For top and bottom rotation, create an animation for top aim, eye level aim and feet aim. send the value of your rotation to animator controller and animate according to it.

How can I rotate an object based on an angle?

I am working in Unity3D and I was wondering how I would rotate a cube based on the angle between the cube and the mouse position. With that I don't mean the mouse position in world space but in pixels.
Here are some pages that'll lead you to your answer:
Input.mousePosition This also includes an example of how to turn screen coordinates into a ray in world coordinates. If you know how far away from the camera you want your point, check out ScreenToWorldPoint for a point instead of a ray.
transform.Rotate To perform a rotation.
The rest of your question is kinda vague--rotating "based on" the angle between cube and mouse position could mean a lot of things. You shouldn't need much more information than this though!