I am currently working on a game
I have two in-the-game objects which are the stone and arrow that attach to the vehicle
arrow has attributes of x, y, z,
rotation, rotation y, rotation z
Changing rotation x will make the arrow turn left and right, the rotation y is the up and down and z is like the wing
What I want is to point the arrow into the position of the stone
I appreciate any help
To make arrow that attach to vehicle point to the stone
I think transform LookAt is what you're after.
arrow.tranform.LookAt(stone.transform);
https://docs.unity3d.com/ScriptReference/Transform.LookAt.html
Related
I'll keep the question short.
I'm making a 2D game.
I have an object, but since it has many pieces, I just out it in a box to have it's hitbox.
If it's going up/down/left/right at perfect angles, I can check for collision because it's just about the left corner and then height and width.
How do I calculate if my mouseX and mouseY collide with it if it rotates at different angles.
Found a formula that x' = x sin A - y cos A or something, but didn't work.
Thank you!
Hello guys I am building a 3D game that player can reshape something like slime with dragging it. the shaping part is alright and I do not have a problem with it.
I use mesh manipulation for shaping my object and I move all vertices within a specific radius of clicked position. but my vertices are moving toward its normal vector I figured that out I can move vertices toward mouse drag vector by just changing normal vectors.
so, here is my question how can I get mouse drag vector so I can change my normal vector to that?
also the player can rotate around X And Y Axis on my object and this makes this problem a little more difficult.
because for example if I see my object from this angle (270,0,0) if players drag mouse to right and down my object should Stretch to its -x Axis and -z Axis.
I want to resize an object along a specific direction in ARKit.
For example, there is a cube on a detected plane and I want to be able to resize the cube in X direction, Y direction and Z direction respectively. Does anyone know how to do this? Thanks.
Background: I am creating an AR treasure hunt app. It is simple, it has a locator that tells you where the treasure is relative to you. I have the camera being the origin and the treasure being an object in AR world.
Question: I would like to rotate my arrow according to where in space the treasure is at. but in 2d. Basically, I would ignore the relative forward plane that is camera.forward.
Example: If the camera rotation is default, the angle can be calculated as atan2(dy,dx). If the camera is looking straight down, the angle is atan2(dz,dx).
What I have tried:
Quaternion lookRot = Quaternion.LookRotation(target.transform.position - origin.transform.position);
Quaternion relativeRot = Quaternion.Inverse(origin.transform.rotation) * lookRot;
Relative rotation is correct in 3d space but I would like to convert that into 2d ignoring the camera.forward plane. So even if the treasure is in front or behind the camera, it should not change the angle.
Okay so I’m hoping this makes sense. You’re going to need some sort of if statement to determine if your character is looking along the x, y or z plane. Hopefully the diagram is clear as to what those parameters are but if not. To be looking in the “x” plane for example, the y rotation would have to be between 45° and -45° or 135° and -135° AND the z rotation would have to be between 45° and -45° or between 135° and -135°.
Essentially what you’ve got is a sphere split into six parts, two parts for each plane along which the character could look. Once you’ve determined which plane the character is looking in you can determine the direction by finding the difference in position between the character and the treasure along the two planes the character isn’t looking along. Then use trig to calculate the angle
Replying to an old thread, but I was struggling with the same problem and found a relatively simple solution:
Project the position of the target (relative to the origin) on a plane defined by the forward vector of the camera. Then just rotate towards the projected point:
Vector3 diff = target.transform.position - origin.transform.position;
Vector3 projected = Vector3.ProjectOnPlane(diff, Camera.main.transform.forward);
origin.transform.rotation = Quaternion.LookRotation(projected);
Calculate the difference in x and y coordinates simply by subtracting transform.x for one object by transform.x of another object and the same process for y coordinates and then use Mathf.atan(difference in y/difference in x) to calculate the angle. Then put the z rotation to this angle and assign the x and y rotation to what they already were.
Turns out there is a very simple way to get relative X and Y of the target.
Vector2 ExtractRelativeXY(Transform origin, Transform target) {
// Get the absolute look rotation from origin to target.
Quaternion lookRot = Quaternion.LookRotation(target.transform.position - origin.transform.position);
// Create a relative look rotation with respect to origin's forward.
Quaternion relativeRot = Quaternion.Inverse(origin.transform.rotation) * lookRot;
// Obtain Matrix 4x4 from the rotation.
Matrix4x4 m = Matrix4x4.Rotate(relativeRot);
// Get the 3rd column (which is the forward vector of the rotation).
Vector4 mForward = m.GetColumn(2);
// Simply extract the x and y.
return new Vector2(mForward.x, mForward.y);
}
Once obtained x and y, turn it into angle using angle = atan2(y,x) as suggested by both MBo and Tom.
This works because of the matrix components of the quaternion can be demonstrated in multiple vectors. Better illustration is found here https://stackoverflow.com/a/26724912.
What is the method to use to rotate an image about a point that is not the image's center point using MATLAB?
Two rotations of the same angle are equal up to a translation. So you can just do rotation around the center, and then translate the image to put your own center of rotation at its old position.
The help to 'rotate' says:
ROTATE Rotate objects about specified origin and direction.
ROTATE(H,[THETA PHI],ALPHA) rotates the objects with handles H
through angle ALPHA about an axis described by the 2-element
direction vector [THETA PHI] (spherical coordinates).
All the angles are in degrees. The handles in H must be children
of the same axes.
...
ROTATE(...,ORIGIN) uses the point ORIGIN = [x0,y0,y0] as the center
of rotation instead of the center of the plot box.
To rotate about a point other than the origin you:
Translate the point you want to rotate around to the origin. For example, if you want to rotate around (3,5), you would translate by (-3,-5).
Perform your rotation.
Undo the initial translation. So in my example you would now translate by (+3,+5).