Prefab in unity appears in a wrong location when drag and dropped - unity3d

I've created a prefab of a trophy in unity. But when i drag and drop prefab to the scene, it appears in the wrong location. You can see at the photo where i drop it(red circle), and where it appears(green arrow).
Same happens when i instantiate it with a script. it appears righter and higher than i click.

As far as I can see, there is an animation in your prefab.
Make sure no coordinate points are registered in this animation clip.

It looks like there is an animation on the trophy. I think what happened was you moved the prefab with recording toggled on and thus, the outcome would be like that. All you have to do is edit the prefab's animation and at the start of the animation, set the position to 0 on all axis. If the problem is still there, check the script, maybe there's something wrong with that? Also if you're still stuck, edit your post with the script. And when I say 'the script' I mean the script that instantiates the prefab.
I hope this helps in some way! :D

Related

Unity Animation - Shifting Position Unexpectedly

I'm learning Unity right now, and I want to animate a sprite of Mario running.
I found a spritesheet and have cut out 3 images.
I select my Mario game object and create a new animation
In the animation window, I put in 3 spites at the times I want to animation the run
When I press play, Mario is running, however he is also shifting position a little bit in the X direction but then resetting as the animation loops.
Why would my Mario object be shifting a little bit as part of the animation cycle? Where would I look to see an attached property or behavior that is causing him to do this? Maybe I moved the object while I had record on? I deleted all the associated animation objects and recreated them but Mario is still moving.
I figured it out. I had a pivot point created on a single frame of the sprites. This would screw it up.

Get Current Animation Frame or Sprite Name

In Unity 2D, is there a way to get the current sprite used either by a SpriteRenderer or an Animation? The idea I have is to have multiple GameObjects to use for a player character, and from the main one which receives animations and the script, edit the others based on the sprite currently used.
Now, I know that to get the current sprite name I can do this:
GetComponent<SpriteRenderer>().sprite.name
But that will only return the sprite used for the main GameObject's SpriteRenderer, and the name of it would not change even as animation changes it in Game Mode
GetComponent<SpriteRenderer>().sprite.name
This 100% does work , just tried it now and it is changing the name for each current sprite that the animator is changing.
You need to give more information and maybe a video since there is a problem somewhere else.

Unity 5.3.8 Animator - Glitch?

I created a bunch of non-AI animations for enemies that do basic back.forth or up/down motions. Everything was working perfect until I started working on the Boss of the level. The boss has his own tag "Boss" and enemies have their own tag as well. Anyway, the problem is when I click start, every enemy leaves the game board. I can see them animated above the game board still doing their routines.
Any clue as to why this happened and how to fix it? I'd really, really hate to have to scrap all the enemies and start from scratch...
I used the Animation tool inside unity.
Extra Note: I created an EMPTY and moved all of my enemies into that Empty object to clean the hierarchy panel up. The animations were fine before this.
************** Currently Resolved **************
Whew! Okay, so apparently Unity doesn't like it when you move your animated stuff into an empty AFTER being animated. I FIXED them by simply removing them from the EMPTY that I had placed them in. However, I'd still like to know why this is. So any useful resources, links, manuals, personal insight/observations or anywhere I can read up on this would be appreciated!
Here is an explanation what happened:
The moment you dragged them all into the empty GameObject I guess this object probably wasn't placed on 0,0,0 in the Scene.
So Unity automatically changed all the local position values of your enemy items to fit the current position offset to the empty object.
Result: In the editmode they don't change their actual global position in the scene but their local position. This is supposed to happen if you just want to organize stuff.
However, now when you start the game and the animations are played, the animators change all the local positions to whatever is stored in your animations.
Result: all objects jump back to their original localPosition which had an offset to the empty GameObject.
To solve this make sure the empty GameObject is at position 0,0,0 and optimally has rotation 0,0,0 and scale 1,1,1 before you drag anything into it.
Easiest way to achieve that is by clicking reset in the empty objects Transform component before starting to drag stuff into it.

Animation Synching in hand to hand fight in Unity 3d

As title suggests I am working on hand to hand fighting system. Now its just a start and I am also not professional so I have setup moves of players and enemy.
Now problem occurs when player hits enemy, it should trigger enemy "taking hit" animation. Now it triggers but both animation of "hitting" and "taking hit" at same time,so it doesn't look at it is meant to be.
So please anyone can set me on right path of what to do for like starting of "taking hit" when "hitting" animation reaches at some key frame or any other way.
I'll post code if you require but only a suggestion or link to some documentation will do.
Thanks
Probably the code is not the problem here. You should detect when the other player hits you, then set the parameter in the animator like this:
yourAnimator.SetBool("TakingHit", true);
Then in your animator, you should put the TakingHit animator and configurate the transition when the TakingHit parameter is activated.
Another thing you should considerate is that if you activate the "TakingHit" parameter bool in a loop, it will start playing the animation in a endless mode.

Scrolling Scene Background - Unity

My title might have actually been a bit misworded, as to be honest I'm not sure how to word it, but basically I'm making a game on Unity and I have my main scene and I am making a main menu however what I want to do is have a, I guess, camera slowly panning around the main scene as the background of the main menu. Not sure if I worded that right or what wording to actually type into Google to research it so I'm hoping you guys might be able to point me in the right direction.
Cheers guys,
Jason
As stromdotcom mentioned you can attach a script to the camera.
It's hard to tell what you're trying to do but if you want to circle the camera around a point...
Try making an empty game object in the middle of your scene and point the camera at it.
Make the object the parent of the camera (using the object and cameras transform properties).
From here you should be able to set the game object to rotate using a script, which should make the camera spin as it is a child of the object.
I have not tried this in Unity but I have used this technique in other programs so I'm assuming it will work. Sorry if it doesn't.
If your scene is already set up then you can attach a script to your camera which simply modifies the camera's transform to move it around the room. You can move and rotate the camera just like any other transform in your scene.
Im pretty sure what you are looking for is "Animation view". Unity has a tutorial on it: https://unity3d.com/learn/tutorials/topics/animation/animation-view?playlist=17099