Scrolling Clone Sprites - mit-scratch

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

Related

Having issues with animations of objects that come from a prefab

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.

Throwing Objects Unity 2D

I'm creating a 2D sidescroller with my own graphics. I've put the main character into Blender and created a few animations resulting in a number of sprites containing the whole character in different poses, and I switch them one by one. Now I want to make it possible for the player to pick up an object (let's say an axe) and throw it. I want the axe to held in hand, meaning it would follow the hand's position. But as there is only one sprite there's no hand's position. The only idea I came up with is to create a new set of sprites with the character holding the axe. Then I would play the "Throw" animation and only after it's been finished I would create an object of an axe and attach a script that would move it further. But my intuition tells me it's too big a workaround and in the end it's going to produce more problems than it would fix. Have you got an idea how this could be managed in a professional way?
Thanks in advance

Making multiple objects with the same shader fade at different times

I have a death transformation for one of my GameObjects which goes from a spherical ball to a bunch of small individual blocks. Each of these blocks I want to fade at different times but since they all use the same shader I cannot seem to figure out how to make all of them not fade out at the same time.
This first picture is the Spherical Ball in its first step for when it turns from a spherical ball to a Minecraft'ish looking block ball and to the right of it is one of the blocks that make up the Minecraft'ish looking ball shown by the red arrow.
Now this is my Inspector for one of the little blocks that make up the Minecraft'ish looking ball.
I have an arrow pointing to what makes the object fade but that is globally across all of the blocks since they use the same shader. Is it possible to have each block fade separately or am I stuck and need to find a new disappear act for the little block dudes?
You need to modify the material property by script at runtime, and you need to do it through the Renderer.material property. When you access Renderer.material, Unity will automatically create a copy of the material for you that is handled separately -- including getting its own draw call, if you care about performance. You can tell this has happened because the material name in the renderer will change to "Materialname (Instance)".
Set the material's fade property using Renderer.material.SetFloat() (or whatever the appropriate Set... function is). Unfortunately the property's name isn't "Fade Factor". You can find the property's name by looking at the shader script, or by switching the inspector to debug mode and digging through the Saved Properties array for one that looks right.

SpriteKit & Swift: How to create level "segments" that are randomly "stitched" together to create an endless game?

The concept that I am talking about is similar to the style of game seen in many minimalistic, popular mobile games such as Color Switch, the Line Zen, Phases, or Bounce. These are endless games composed of a series of "levels" or "rooms" that are placed in a random order, and are one after another, creating the effect of an endless game. The key thing is that the challenges in each level are not random, they are drawn up before, and if that certain level is chosen randomly, it appears on the screen and the player moves through that level.
I think this concept might be called procedural generation, though I'm not positive.
How would I do this in SpriteKit using Swift? I'm not really sure where to start, maybe create a function for each level segment and, every few seconds, choose a random one to put on the screen?
Any help is appreciated!
Thanks so much!
Procedural generation is the name of the concept you are describing.
The approach will change a bit depending on the type of game you are trying to make but let's look at procedural generation in an infinite runner game. What you want to do is set up a buffer of level segments. The total size of the segments in your buffer should be at least twice the size of the screen. Every segment should be a child of the same segments node and they should be positioned so that each starts right after the previous one ends.
When a segment moves off screen (the player passed it):
remove that segment from the segments node
initialize a new segment (probably from a sks file)
add the new segment to the segments node
position it behind the last segment in the segments node.
The logic you use for choosing the next "random segment" is up to you. It can be truly random or you can fine tune it for the best user experience (avoid repeating segments, avoid segments that would ruin the flow, etc).
The key is to remove segments as they go offscreen and add a new one at the end of the buffer. This must be position based, not time based (time is less reliable even when the game scrolls at a constant speed).

Unity3d Transform issues when trying to re-parent a Gameobject with sub-Gameobjects

I am trying to grab a Gameobject that's placed in the correct spot and re-parent it to different Gameobject transforms using code. I manage to do this by using ..transform.parent = parent.transform but the rotation and position get messed up. How can I keep it's rotation and position when re-parenting?
Thanks!
Always use gameObject.transform.SetParent(anotherGameObject), or you risk exactly the sort of phenomena you've described. See SetParent docs; there is a second parameter to consider.
The form mentioned in the question still works in many cases, but has been deprecated for a while.
Place all game object that you want to parent, to empty game object(example:"EMPTY\PARENT\EMPTY\CHILD") with scale 1:1:1(in editor)or re-scale your parent game object to 1:1:1