I'm having a lot of trouble figuring out how to orient my model. I noticed the problem when I ran into trouble getting my character to rotate in the direction of movement. After significant trial and error with functions like LookAt() I realized it was because my character's z axis (forward vector) was not facing the same forward direction of the character. After rectifying this in Blender I imported into Unity and walah the z axis is in the same direction as the character. But when I play the game and the animation starts, the z axis points in the wrong direction again! Any idea why Unity is doing this? fyi I modeled the 3d object in blender.
AFter starting the game (character doesnt face z axis) :
Before starting the game (character faces z axis)
If your scene is modified when starting the game you can assume that it's logic you've created, likely scripts, that affect the Game Objects.
Like the comments suggest, try disabling the script components on your game objects to see what causes it.
Sometimes you may want this logic in your editor scene, so that your Objects are rotated the way they will be when the game starts even when you're working with the scene.
Imagine having a top-down game with a camera that follows the player and is always rotated towards the Player. You'd want this camera to rotate towards the player when you move it around, re-arranging it so that it gets the perfect angle. To achieve this you may use [ExecuteInEditMode]:
[ExecuteInEditMode]
public class LookAtPlayer {
Transform player;
void Update() {
this.transform.LookAt(player);
}
}
If you have re-imported your model and adjusted it's X/Y/Z axis while already having created an animation, then it is very likely that your animation is using the wrong Axis.
You can either copy the values of your animation onto the correct axis, or if the animation isn't very complex I advise you to recreate the animation from scratch.
Related
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.
Sorry I know the title is really confusing.
Basically the camera and hands are nested under an empty object. This empty object is then used to rotate the character and teleport the character. Thing is, the camera is able to freely move around and away the empty object. Making rotation seem like you're running in a circle instead of just rotating. Then when you teleport it's a little offset. Like if you shoot the teleport beam straight down you move because it's teleporting the empty object to the camera which moves the camera.
So if the headset and camera aren't exactly on top of the empty object everything gets wonky. I understand the problem just can't figure out a solution.
I tried resetting the position on every teleport but you can still move away and spin in circles. As well as resetting resets the orientation and that's not exactly what I need.
Any help would be greatly appreciated.
There's a few ways to approach this. A crude, and not very elegant solution would be to parent your camera parent to yet another object, created in runtime, that would assume the position of the actual player camera when the rotation starts. You can reparent objects dynamically, so you could rotate this newly spawned object, which would give you the desired effect, and then loose the top parent when the rotation stops.
Alternatively you could move your camera parent as you rotate it, based on transforming the position relative to the player camera position. A bit more elegant but there's probably a few lines of math that you would have to write
Kinematic based world being messed on movement
Hello, I have been developing a humble AR-based game in Unity3d. Until this point, I have been using Vuforia to deploy my scene on a (multi)tracker. However, I have been doing tests with Kudan and I´m quite happy with its tracking performance when using a tracker.
http://i.imgur.com/nTHs6cM.png
My engine is based on collisions by raycasts and not "UnityEngine.Physics" (Almost Everything is Kinematic). I have stumbled into a problem when I deploy my 3d environment on a tracker using the Kudan engine, my whole physics get messed up. If the marker is moved the elements move with it but the axis seem to change with marker but my physics seem to respond to my old axis orientation. My characters are always standing upward in the world Y axis (not the local inside the tracker). Another issue is that my player 3D asset keeps switching between "standing" and "falling" status and eventually clipping and falling through the floor (this is probably due to the jitter in the camera detection).
http://i.imgur.com/ROn4uEz.png
One of the solutions that come to mind is to use a local coordinate system but I hope that there is an alternative solution since when I was using Vuforia I did not have to do any further corrections.
Any links or feedback are appreciated.
You could use transform.InverseTransformPoint and transform.InverseTransformDirection combined with Quaternion.LookDirection to get the position and rotation of the kudan camera relative to the MarkerTransformDriver object. This will allow you to position a camera in world space and keep whatever content you want to augment static at the unity3d world origin.
cameraPos = markerTransform.InverseTransformPoint(kudanCamera.position);
cameraRot = Quaternion.LookRotation(markerTransform.InverseTransformDirection (kudanCamera.transform.forward));
I have been creating a physics Model Newton Cradle(pendulum) in Unity 3D, but have been facing difficulties in rotating and zooming camera around object, applying momentum conservation for pendulum objects.
I'm not sure if this will help but based on the title of this statement[?] I'm guessing you want to rotate the camera around a target. This is some simple code that may help you on your way.
target=GameObject.FindWithTag("Cradle").transform;
transform.LookAt(target);
transform.Translate(Vector3.right * Time.deltaTime*2);
edit the number after deltaTime to change the speed and the Vector 3 for the translation. Obviously change "cradle" to whatever the tag of object you want the camera to focus on.
I am working on a tabletop game that user controls using accelerometer in the phone. It is pretty similar to Labyrinth on iOS.
The scene contains a tabletop created using planes and cubes, and a sphere as a ball. As it works in Labyrinth game, on tilting phone ball should drop to the tilted side, while the camera stays centered to table. I am trying to do similar thing where user tilts the phone, and objects on table move to tilted side.
Currently, I add the x and z component to Physics.gravity on tilt. Sadly, this change in gravity does not affect the ball which stays put on the table. Use gravity is selected for the ball, and it drop down from height to the tabletop initially and then comes to halt. After the initial drop, ball does not react to any gravity change.
I have also tried rotating the whole table, but using transform.rotate does not work either. The table rotates perfectly, alongwith the camera, but the ball stays put hanging in the air. So, currently I am out of my depth about the issue.
Is there any other way to allow tilt action registered, so that ball moves to the tilted direction? I cannot use addforce function, as there are multiple objects which need to react to tilt, and it will be difficult to keep track of that many addforce calls. How else can I get it working?
See this post for some related information.
As for why your sphere is sticking to the table, can I assume your sphere has a rigidbody? If so, you need need to wake it up:
if (rigidbody.IsSleeping())rigidbody.WakeUp();
Ideally you would make that call only after detecting a change in orientation/gravity, not every frame.