Having issues with animations of objects that come from a prefab - unity3d

So let me preface this that, i am very new to unity this is my first week actually lol and i couldnt exactly find anything that would answer my question.
Anyways, i have this like thwomp object that has 3 animation states crush, reset, and wait. and it goes up and down as you would see it normally just on a timer because of the wait. it is done by adding the position property and then moving the y up and down. pretty simple i think, couldnt think of anything better. it works perfectly just like i want it too.
but when i made it a prefab and try to make more of them, the animation for the copies have the same x and y as the original. so like even though i can change the base like default positioning of them whenever the game starts and the animation plays they just perfectly overlap with the first original one that the prefab was made with. when i try to change the x coordinate on the copies animation it updates the x coordinates for all them. this happens even when i delete the prefab and just manually make copies with ctrl + d as well (im not sure if this any different?) . i assume this is because they all share the same 3 animations so when you change the animation it changes it for all them and that makes sense.
but i really dont want to make 3 seperate animations for each replica thwomp i make, i feel like there definitely has to be a better way. my original thought of how it would be was they would share the same animation, but like within the object its self the animation values like the position are exclusive to the object so they could differ inbetween each one.
ill include a link a picture to like further convey what i have going on here so its easier to understand. https://imgur.com/a/78q6VCI

You want to change the localPosition not the world position. This thread has a little discussion about it but basically you need to use the x, y, z you get from the Animator as an offset to localPosition.
Pseudo code:
transform.localPosition.y += animators position.y
https://forum.unity.com/threads/playing-animation-local-to-position-in-unity.53832/#post-489101
Special note: Using an animator is pretty heavy. For simple stuff like this I would suggest just scripting it.

Related

Unity: skinned mesh vertexbuffer output slightly different than correct results

It’s like this hip is stuck in place, with in the pictures(being at different times in the animation since I can’t upload a gif) the red wireframe is the drawing of the raw output triangles and everything else being default unity, aka the correct output
What am I doing wrong? What am I missing? This has been driving me nuts for 2-3 days now, any help is appreciated
As you do not post any code, I will try to do some guessing over what is going on. Disclamair: I actually happen to run into similar problem myself.
First, you must know that Update's of MonoBehaviour are called in random order (not neccessery random-random, but yous see the point). If you bake mesh in one component, it can still be one-frame late to the Animator component.
There are actually two solution of this case: first is to specify the order of Script Execution Order in Project Settings, while the second is to use LateUpdate instead of Update when updating mesh after skinning.
The second problem you might have run into is scale / position of skinned mesh. Even if it does not contribute at all to the animation movement it can still wreck the mesh baking collision later on.
To fix that make sure that all your SkinnedMeshRenderers objects have Local Position, Local Rotation and Local Scale set in Transform component to identity (0,0,0 for position and rotation, 1,1,1 for scale). If not - reset those values in editor. It will not change animations, but it will change mesh generator.
If both solutions does not work, please describe the problem more thoroughly.

Unity character flies easily

I have been using Unity for a while and still Im not sure about some things, I know there are like 5 different ways to move our character (not using prefabs like for 1st or 3rd person controller I mean just code from scratch) so far for moving a character on a terrain I think setting the speed of the rigidbody works overal for me, just setting the x and leaving the y component as what it was before assigning that, so that gravity effect is kept, overal it works, I manage to collide with wall and other objects, manage to go on terrain and could add jump later in same fashion, but the trouble I find is that my character flies when it steps over any small object like a stone on ground, if he goes over it he starts flying, not a big distance but definetly looks like walking on the moon maybe, also I see that if I have a bridge that is lower in the middle part of it (like U shape) well the character goes like flying from the begining almost until the middle or so, as said works like being on the moon, however gravity seems ok on other objects, I know I can change the gravity value to be higher but Im affraid I could be breaking all that so my question is, is there a better way to move a character on ground that will work better without changing the gravity value? I guess that it can work right without affecting this value, I used other method to change velocity and adding a certain value to the y component but again I see it not right as an apparent correct value for small stones and small objects makes it hard to go over slopes too, any help is greatly welcome =).

Unreal Engine 4 - Add offset to character movement

I just started (yesterday) using unreal engine and I need to simulate a drunk character using BPs.
I'm using two camera shakes (one for standing still and one for walking) but I want to add some "displacement" on charater when he's walking.
Basically I want to define a random float to be added to X axis location in order to make character wobble smoothly.
It will be acceptable even if there's a way to make the character move along with the camera when it's shaking.
What I tried until now is using AddActorLocalOffset and a timeline to lerp between actor's location and actor's location+offset, but both are very choppy to me.
Maybe it's a noob question but as I told I'm very new to this and need it for a quick work.
Any suggestion?
Thanks
If you are targetting physically correct model, you should use AddForce (UE Docs). But this approach would require implementation of a "drunk animation" where your character will modify it's movement animation to "compensate" this force by stepping aside etc.
Another (much more simple) approach is by using AddMovementInput. This example can be seen here: UE Aswers. In this case, you are basically simulate player's input by adding small amount of side force here and there.

Scrolling Clone Sprites

I'm attempting to make a code in which I have a sprite act as the main terrain sprite (aka a tile) and have clones of that sprite stack on to the end of it, while maintaining the scroll code, which allows the x positions of the main sprite and the clones to change as the player pushes down on the "a" and "d" Key, While maintaining their proper positions in line. The issue I am having is that for some reason the third costume in my terrain doesn't seem to appear when its clone is created to act as the last tile in line.
I think the issue is that it's already created all the clones, but the first terrain block it clones off of spawns at the same time as the new ones.
By the way, Scrollnum determines the position in the line.
When your clone starts, it goes to the next costume, but since the base spirte's costume is always the first, the clones' will always be the second. You need to set the costume according to the clone ID. That variable (scrollnum) should be "for this sprite only", by the way.
I have had a similar problem, and it's possible that you are not using the right costume number. Try going one costume number down.
I completely forgot about this question but I did manage to figure it out in the and I thought I should post the answer considering that it may be of help to others.
Let me explain this code a bit, as shown in the image this uses a block instead of the repeat loop I attempted to use mainly due to the ability to use it more often as well as condense my code. The CloneX variable is refers to the tiles X positioning as a multiple in reference to the screen size. The equation when used looks like this: (CloneX * 480) + ScrollX. The TileX variable refers to the amount in which you want cloned.
This is how I ended up calling it. I ended up setting the costume to the one I needed for the level in order to start the generation of tiles. Then I initialized for the variables in the block]2

Setting up a power meter in cocos2d

I am a straight noob. Everyone else says it, but I'm dead serious.
My question is, what is the best way to make a power meter to move a object? Meaning, how to set it up so that the longer the player holds the more power they get. Also how, would I incorporate physics?
What I'd like to accomplish is to have a player holding onto something so that when he taps on the screen and hold he powers up, and when he lets go he throws the object a certain distance.
just checking if the there is any thouch sequence or not is rather an easy thing, you just have to overload two functions for your scene class, one to inform you whenever a touch sequence begins and one to tell you touch is ended. the source code example is describe in this link. after than i think you need a gauge to show how much power is gathered so far, the easiest way is to use a texture with full power shown in it and the set it as texture and then show it little by little as the power goes up just as the code below:
// to create the gauge with zero power
CCSprite *s=[CCSprite spriteWithTexture:[CCTextureCache addImage:#"gauge.png"] rect:CGRectMake(0,0,0,10)];
// and then whenever the power changes you call this method
[s setTextureRect:CGRectmake(0,0,power,10)]
note that in my code i am using a 100x10 texture (power is somthing between 0..100 and texture height is 10 as the last parameter in both CGRectMake functions)