#๐ผ๏ธโ2d-tools
1 messages ยท Page 36 of 1
are you changing your text in update?
uhh
sort of
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
_inRangeNpc = true;
}
else
{
_inRangeNpc = false;
}
}
private void Update()
{
if (_inRangeNpc == true)
{
if (Input.GetKeyDown(KeyCode.E))
{
_dialogue.StartWriteTextCoroutine();
}
}
}
this is in update
but
the method itself
and other methods
arent\
public void StartWriteTextCoroutine()
{
StartCoroutine(WriteText(input, textHolder, textColor, textFont, delay, sound, delayBetweenLines));
}
public class DialogueBaseClass : MonoBehaviour
{
public bool finished { get; private set; }
protected IEnumerator WriteText(string input, Text textHolder, Color textColor, Font textFont, float delay, AudioClip sound, float delayBetweenLines)
{
textHolder.color = textColor;
textHolder.font = textFont;
for (int i = 0; i < input.Length; i++)
{
textHolder.text += input[i];
SoundManager.instance.PlaySound(sound);
yield return new WaitForSeconds(delay);
}
yield return new WaitForSeconds(delayBetweenLines);
yield return new WaitUntil(() => Input.GetMouseButton(0));
finished = true;
}
}
it'll only write the text when you press E. you have to be focussed on the game view for it to detect keypresses
well lol
the functionality works
look at the right side
notice how it actually writes, without showing up
getting there ๐
Watch this video in context on Unity Learn:
https://learn.unity.com/tutorial/onmousedown
How to detect mouse clicks on a Collider or GUI element.
dunno, i just found this.
very much it is, to my problem atleast
oookay bro
public class DialogueBaseClass : MonoBehaviour
{
public bool finished { get; private set; }
protected IEnumerator WriteText(string input, Text textHolder, Color textColor, Font textFont, float delay, AudioClip sound, float delayBetweenLines)
{
textHolder.color = textColor;
textHolder.font = textFont;
for (int i = 0; i < input.Length; i++)
{
textHolder.text += input[i];
SoundManager.instance.PlaySound(sound);
yield return new WaitForSeconds(delay);
}
//yield return new WaitForSeconds(delayBetweenLines);
//yield return new WaitUntil(() => Input.GetMouseButton(0));
finished = true;
}
}
how much is it related now?
@still tendon realise that you're not the only one in this chat please
well, after i got ignored 3 times in different chats, i have realized that, thank you very much
Manners go a long way
exactly, manners
Consider being patient and polite. Also word your questions better and please for the love of god don't send one word messages in succession. You're making it really hard for me to want to help you
And how much research did you do on your own outside of asking twice?
so, they do move now with rigidbody and onMouseDown, but on mouse down breaks the functionality so that they teleport upwards and instead of following my mouse
show your code
and how's that going for you
im not going to switch the whole text method because some person told me that its better to use, when unity methods already suffice
besides, that would lead to more research, because textmeshpro is more for hd not pixel games
Untrue, TMP has much more functionality. You can use it wherever
sure thing
using System.Collections.Generic;
using UnityEngine;
public class DragY : MonoBehaviour
{
Vector3 first, second;
public float speed = 15;
void Update()
{
void onMouseDown(){
if (Input.GetMouseButtonDown(0))
{
first = Camera.main.ScreenToViewportPoint(new Vector3(0, Input.mousePosition.y, 0));
}
if (Input.GetMouseButton(0))
{
second = Camera.main.ScreenToViewportPoint(new Vector3(0, Input.mousePosition.y, 0));
Vector3 diff = second - first;
transform.position += diff * speed;
first = second;
}
}
}
}```
i also tried a more reduced version where there was only onMouseDown without any of those class object variables. and inside onmousedown i had put the latter if clause
im done
Your onmousedown function is inside your update, I don't know if that's intended
I'm more amazed that it'd even compile like that
@rose prawn also you have to strictly follow the case of the function in order for Unity to recognise it as one of its events
OnMouseDown()
i did that after my first try. the functionality remains the same.
you see, i'm a java programmer and during these two days our programming teacher set up a game jam for those who were interested.
thing is, i (we) have been thrown into unity and C# just under 24 hours or so and none of us knows any unity or C# syntax. so this is more like googling 101 for all of us
an experiment of sorts if you will
The class structure in java and c# is pretty much the same
yeah, i know that much
it's more like i don't know what any of the methods or what do they do. the logic just isn't there even if i know the somewhat similiar syntax
wait
That assumes that you haven't moved your camera and it's still at 0,0,-10
https://hatebin.com/ysjiqatkdr edited it, didn't realise I had done it a little wrong
@rose prawn here's a complete list of the unity event functions, under the Messages category https://docs.unity3d.com/ScriptReference/MonoBehaviour.html
thanks a ton, but there one itzy bitzy thing.
Also that code will allow you to drag in both x and y, not just y
we are recreating this
ah okay
so it's essential you must be able to move it only x or y
beautiful, now let me read and try to understand it
just a sec
onmousedown and onmouseup are implementable methods?
They're listed in the doc I sent you
aight
will look into it
oh my this is bloody beautiful
thank you
i know where to go from here. you are amazing :3
๐ฅณ
I've got everything set now
Idk if it's improved anything though
Falls below 60 FPS at around 300 bullets
What's your bullet object look like?
Like the actual sprite or
No like what scripts does it have on it
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
This
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
And this
Along with a RigidBody2D and CircleCollider2D
It doesn't look terribly demanding
As a rule of thumb, GameObject.Find() is pretty slow, so if you're doing that 1000 times it'd be noticeable, however you only do it once per object so it shouldn't be an issue once it's assigned
also you can see the fps in the stats menu at the top right of the game view
just to make sure it's not your FPS code that's giving a wrong number
do you need to be doing animator.SetInteger("setColour", bulletColour) every frame?
@hearty anvil
Hmmm my FPS code is actually giving me an incorrect number
Interesting
The real number is in fact higher
Phew
Panic over
Ohhhh thank God
Okay so I realised having over 1000 bullets may be too much for Unity, at least with my current level of optimising
So I decided I'll have a universal max of 600
Seems like the game can handle that fine at an average of about 110 fps
Still, I want to add more things to the game such as possible blending effects on the bullets as well as some particle effects for explosions and all that stuff. That and a working background. Does that sound feasible to do without falling below 60fps?
Oh by the way is there a way I can access the variables of the enemy bullet component so I can like set the speed when I activate one?
make them public
my objects collide correctly and they stay within the boundaries...
but only when pushed by another object
using a mouse they will go over the designated area
somewhere on the interwebs someone said something about moving them by velocity and not by mouse
also, why do they jiggle when pushed against a wall? it doesn't really matter since in the end you are not supposed to be able to push them with other ducks
when calculating velocity for movement do you do it based on frames per second?
for example if you've got 6 frames for walking and 8 frames for jumping then walking should be slower?
srsly dunno
seee here
it breaks after spawning about 8 objects (40 beats into the game). It seems fine every time before that tho
I don't see how the code you posted would cause the problem you describe. The problem is likely elsewhere.
i got it fixed
but now there's a new problem
if i move it with enough speed, the collider ignores it
all i had to do was transform it, not by the location of the mouse, but the speed that comes with it
oh and also this brings back the previous problem where multiple objects are moved at once
Cinemachine + URP + Unity 2d + Pixelart + Cinemachine pixelperfect = Jittering sprites while moving camera. Any solution?
try to set Interpolate to "interpolate" on rigidbody
so I am trying to create a separate dash action script for the player (i want enemies to use this ability too so i split them) and i don't understand game objects very well.
How do I make it so the dash script gets code from the player script (x and y movement) and modifies the player's movement accordingly (to make the player dash)?
What you want to do can be accomplished a couple of ways. 1) The Player script and the Enemy script can derive from the same base class--MoveableCharacter, for example. The Dash script can then get a reference (in Start(), for example) by using GetComponent<MoveableCharacter>(). 2) You can use scriptable objects. I suggest you use the free ScriptableObject-Architecture asset on the asset store for this. If you use scriptable objects then the Dash script will not need to know about the Player script or the Enemy script. It can get access to the necessary information through scriptable object fields.
Example use of scritable object fields...
[SerializeField] private FloatReference _playerMaxHealth;
[SerializeField] private FloatReference _playerCurrentHealth;
I see, thank you
are there any tutorial videos on using scriptableobject-architecture?
Yes, that particular asset was inspired by some Unity conference talks. https://youtu.be/raQ3iHhE_Kk https://youtu.be/6vmRwLYWNRo
Scriptable Objects are an immensely powerful yet often underutilized feature of Unity. Learn how to get the most out of this versatile data structure and build more extensible systems and data patterns. In this talk, Schell Games shares specific examples of how they have used the Scriptable Object for everything from a hierarchical state machine...
Get the assets here: https://bitbucket.org/richardfine/scriptableobjectdemo/
This session goes over ScriptableObject class in detail, compares it to the MonoBehaviour class and works through many examples of how it might be applied in a project.
Richard Fine - Unity Technologies
There is also documentation on the project's github page.
oh cool
it doesn't recognize floatreference
using ScriptableObjectArchitecture;
oh, thanks!
Hello! I'm new to unity, and want to get to experience c#. Is there some articles you guys recommend?
I think these are what most people are recommending these days. https://learn.unity.com/project/beginner-gameplay-scripting
How to can i save and load a object with all parents objects?
by creating the parent object with sub objects all attached? otherwise if your talking about setting flags would have to save them somewhere then load them
Hi, im having a problem with OnCollisionEnter2D, theres already 2d colliders on both of the objects but the function wont get called, any suggestions? Thank you
Okayz thank you
How can i make it so that when the red box collides with the white one the white box gains a certain amount of impulse?
@earnest wind Im a noob but maybe use OnCollisionEnter2D and then add force in the opposite direction?
That's what i have done
What is happening instead?
You're asking for 2 frame perfect events there
The exact frame that they collide, and the exact frame that space is pressed
If you want to check if they press space while they continue to collide, then use OnCollisionStay2D instead
Otherwise if you want to check if they're holding space at the point of collision, use Input.GetKey(KeyCode.Space)
Yeah that was the thing
Also how could i do so that it gets impulse depending from where the red box is?
Like, if the red box collides with the white box in the right side the white box gets impulse to the left
instead of new Vector2(0,5) you can do something like redbox.transform.position - whitebox.transform.position which would give you a direction pointing from the center of the red box to the center of the white box. You could then multiply that by whatever force you want
Doesn't work 
What does it do instead
It doesn't do anything at all
Also, i guess if i have the red box and the with box in diferent scripts i need to instantiate one of the right?
void OnCollisionStay2D(Collision2D collision)
{
Vector3 dir = collision.transform.position - transform.position;
if(Input.GetKeyDown(KeyCode.Space) * collision.gameObject.CompareTag("Cid"))
rb_caja.AddForce(dir.normalized * 5.0f, ForceMode2D.Impulse);
}
Assuming this script is on the white box, you can get the red box from the collision parameter
Oh gotcha
It works but instead of going the opposite direction it goes in the same direction as the red box
oh, flip the values around then
is it possible to detect what type of tile the raycasting is looking at?
transform.position - collision.transform.position
What should the output be and why
hey guys, I have this Tile Map with a composite collider component on it, how can I get all the platforms positions (I want to dynamically spawn monsters on them) ?
Hi, I'm trying to deal damage to a new enemy that I have created but I cannot because I have made a new script for him.
private void DealDamage()
{
Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(AttackPosPlayer.position, AttackRange, WhatisEnemies); Debug.Log("DealDamage Initiated");
for (int i = 0; i < enemiesToDamage.Length; i++)
{
enemiesToDamage[i].GetComponent<Enemy>().TakeDamage(dealsDamage); Debug.Log("Dealt Damage to Enemy: " + enemiesToDamage[i]);
}
}```
This is the script for the player
If i want to deal damage to, lets say a few enemies should i add them too in the loop where enemiesToDamage[i].GetComponent<Enemy>().TakeDamage(dealsDamage); Debug.Log("Dealt Damage to Enemy: " + enemiesToDamage[i]); is
The script for first enemy is "Enemy" and second is "EnemyGhost"
or can i somehow have the player identify which script is on the enemy
Fixed it myself
I'll post it here just if anyone wanted something similiar
You can use if(enemiesToDamage[i].name.contains("Keyword"))
Use Random.value or Random.Range() as follows.
float f1 = (Random.value < 0.5f) ? -1.0f : 1.0f;
int i1 = (Random.value < 0.5f) ? -1 : 1;
float f2 = (Random.Range(0, 2) == 0) ? -1.0f : 1.0f;
int i2 = (Random.Range(0, 2) == 0) ? -1 : 1;
Debug.Log($"f1 = {f1} i1 = {i1}");
Debug.Log($"f2 = {f2} i2 = {i2}");
what does ? -1 : 1; mean?
thank you very much
Hi! I'm making a game an easy 2D game that moves jump and do other stuff (not yet in the code), but I have an issue, when I code the mode everything is fine, but whenever I enable the Animator (so it looks better) I can't move on the X axis neither on the Y axis, I struggled all day yesterday with that and still cannot find a solution so I'll be very thankful if someone can help me with that, my code looks like this:
I know this is for code but could someone help me. whenever i move it like paints itself behind the actual sprite
im new btw
I'm using a tileset collider 2d on the ground and a box collider 2d on the player but the player randomly gets caught on the platform and stops moving, does anyone know how to stop this from happeneing?
- Try using a composite collider 2d on your tilemap and/or 2) Try using a capsule collider 2d on your character.
Watch this video in context on the official Unity learn pages
http://www.unity3d.com/learn/tutorials/topics/2d-game-creation/tilemap-collider-2d-and-composite-collider-2d
In this live session we will explore worldbuilding in 2D using Tilemap and 2D Cinemachine. Tilemap makes it fast and easy to create and iterate level design cycles right in Un...
That video will show you how to setup a composite collider on your tilemap.
thank you
I don't want to use a capsule colider because if you get too close to the edge you end up sliding off
It worked! thanks for the help @tropic charm
is there a easier way to make your tiles have a collider other then making a colider
or like how do you make a collider for a slope
@formal lava Usually the collider that unity generates based on the sprite works fine.
Just make sure the tile's Collider Type is set to Sprite.
ok thanks
See this also in case you want to change the default. https://stackoverflow.com/questions/58707598/how-to-change-collider-in-individual-tile-in-tilemap
where is the pixels per unit couse i dont see it when i click on the sprite
click the sprite in the explorer or whatever it's called, then check the inspector and it should be there
are these blue lines part of the sprite or just camer/scene
@formal lava That might be tile bleed. It's a big pain to deal with.
this function only works when the game starts but not when i update the health value. am i supposed to call the function somewhere?
@chrome anchor are you familiar with events?
not really, i did make a game event listener though
You would call HealthChanged whenever you actually change the health, e.g. TakeDamage() or Attack()
https://github.com/DanielEverland/ScriptableObject-Architecture/wiki/Quick-Start
this tutorial says it's supposed to update by itself (i use scriptableobject-architecture)
yeah i did that part here
What you have looks similar to what I had when I went through that same example and I didn't have a problem. Obviously, you have to change the value of that variable at some point...
how do I change the collider of a tile from a tile map
_playerCurrentHealth.Value -= 1;
hm
I think it's just the slider having issues. I ran a command that drained my hp every frame and it worked
Thank you for your time though
So you were changing it in the inspector? I just tried to change it in the inspector too and it didn't call the event. So that sounds like a bug since that's exactly what he is doing in the example.
Yep, that was the case for me
Someone has a 29-day old pull request for it. https://github.com/DanielEverland/ScriptableObject-Architecture/issues/141
It wasn't an accident, though. It is pretty obvious that it was intentionally pulled out.
is there any way t recover an unsaved file
theres tilemaps in my main camera object. Are these supposed to be here
@formal lava yes idk how but you can
Which editor are you using? Some are smart enough to do that.
no my entire gaddamn unity game
Unless it is in the OS's Recycle Bin then it is likely gone. Although, a "unity game" is several files so you would have had to lose the entire folder.
well the thing just crashed
anyone know?
all my files seem to be here just all trhe charecters and shit is off the screen
and delted fronm the hierachy
No, there shouldn't be a tilemap on your camera.
i think ill be good all my scripts are still here
source control
Black lines keep coming up in my game. Is it a rendering issue? Do you need a video?
do you think this is okay? being able to be a few pixels over before falling
You're doing a tile map, right? The problem is likely tile bleed.
Users will likely be annoyed by that.
not sure what i could do
I always err on the side of making the box collider a bit smaller, rather than larger. Nothing more annoying than getting hit by projectiles when the player feels like it wasn't even on them.
i understand but i don't like pixels clipping through stuff
Why not try a polygon? @orchid pewter
i don't know i am learning
i guess its fine for now hehe
Hint: There are other colliders rather than just the box.
i'll make a note of it for future
all the tutorials use box colliders lol
Sure, but you don't have to, it's your project.
i know
What if you want to change something else but the tutorial doesn't?
You might be screwed, or could be great. Worth exploring.
i already do that within limits
You might want to try:
https://docs.unity3d.com/Manual/class-PolygonCollider2D.html
yeah i thought the alternative would be messy hehe
maybe i could work around it with new pixel art
how do I make my animation slower so the players not on gfuel
@still tendon in the animation tab click the three little dots top right corner, then enable Show Sample Rate, i change 60 to 12 or 10 and it'll space the animations apart
Thanks!
how do I delete a transition
select it and click delete?
why is it able to see the like icon of the light
That's a gizmo. Click the left-hand side of the 'Gizmos' button (not the arrow) to enable/disable them.
Anyone know a way to "stick" an object to a 2D animation? Like put a separate sprite over the moving character's foot for a shoe. I know I can maybe lerp it to match the animation, I just dont know if anyone has done something like this before. These will be different items that will change
Put your shoe as a child of a transform that is being animated
Its just a sprite sheet, so there really isnt a transform for that ๐ฆ I think the only way is to do it through movement within script to match the animation speed
If it's a Sprite sheet then it's not straightforward
But you can always add an empty transform to your animation clip
And just match up the keyframes to the sprite manually
No script required for that
@brisk badge The tutorial seems to be pretty much in 2D already.
You probably only need to drop the y component of Vector3 and use Vector2 instead
@brisk badge Don't cross-post the same question to multiple channels.
thx
Hi all, I'm starting in the game development world now but I already have a good experience in C#.
Do you guys have any starting point to share with me? I'm studying random things in the unity 2D engine but should be better if someone give me some ideas on how to start with it or something like that.
Thanks a lot ๐
@silk pendant It is still advisable to go through the course like "Create with Code" (pinned in #๐ปโcode-beginner ) to familiarize yourself with engine itself in a more methodical way.
Thanks a lot buddy. I'll take a look on it.
Hi im a beginner unity user who has used Godot for a year now but i want to use the firebase capabilities of unity and I was wondering if there was a way to save a gameobject as a file and then place it into multiple scenes
for ex: a player who is need in multiple level scenes
i think you can just drag it to the project window
You can keep runtime data in ScriptableObjects, which when used as assets can be referenced from multiple scenes. Or offload data to Json on exit if you need persistence between runs.
if i've got 16 pixels per unit how do i jump one unit with velocity?
i've read conflicting help like if i wanted to jump 100 pixels it would be 100 / 16 = velocity but that doesn't work unless i'm doing something wrong
One unit is one unit, you donโt need to calculate using the pixels per unity if you are setting them properly
so one velocity should equal one unit then?
so i should travel one unit every second?
I think it will
16 pixels per unit means each unit has 16 pixels
Not that one unit is the size of a pixel
Check your import settings of the sprite
one unit is 16 pixels
so if velocity is 1 then i should move 16 pixels per second?
Unity velocity is in units/s. To convert those units, it solely depends on the scale you created your game in. If you let 1 unity unit = 1 meter for all your objects when you create them, then velocity is meters/s. For 2D, the default pixels per unit is 100, so if your velocity is 1, that would be 100 pixels/s.
when i make velocity 1 i'm not moving one unit per second
rb.velocity = new Vector2(1f, rb.velocity.y);
wait maybe it does ๐ฎ
maybe its the gravity of jumping that is messing things up with my maths
seems perfect when walking
Friction and gravity may affect the velocity
Check on the Rigidbody info to see that velocity is exactly 1
yeah i need to calculate my jump to include gravity
just need to figure out how to jump one unit a second if gravity is 9.8
Well you'll never move upwards at a constant velocity as gravity is accelerating you in the other direction
What's your end goal?
just wanna figure out how to change my jump height for puzzle platforming
Learn how to create a 2D platformer controller in Unity that can reliably handle slopes and moving platforms.
In episode 03 we create a system for keeping track of where collisions occur, implement jumping, and refine our player's movement.
Download source code here: https://github.com/SebLague/2DPlatformer-Tutorial
If you'd like to support th...
^ That video has what you're looking for
thanks
Change the velocity until the height is like you want
that is one method yes
The video I posted uses kinematic equations to specify the max Y position of a jump and allows you to determine the exact velocity needed for it
Wow, thatโs very cool
Mathematics โข๏ธ
Iโll add it to my playlist
I'd sub to the guy, he's been invaluable to my learning
there are so many small youtubers that have better information than larger channels
He definitely deserves more subscribers, however I've never heard anyone speak poorly of him
I am making a top down 2d racing game I have made the player and for the AI I am making it follow nodes. But when I make it rotate towards the next node it like rotates in the wrong way. https://hatebin.com/ghteshrutq
https://gyazo.com/854894c98b7de039b4bda149d8cdde43
Anyone know how I would fix this sort of floatyness from the player when their falling? I have to use my gravityscale 0 system to get the ramps working properly but I don't know what else to do; heres the code:
____
https://pastebin.com/5UXrc9y6
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
(ignore, solved)
How did you fix? @forest hedge
completly re-did my code after following a tutorial lol
so not really fixed
just scrapped and redid
Ah ok was just curious if there was something specific you put in.
How do I make sprites (using 2D URP) cast and receive shadows? I've looked online, but the only posts I've found are for 2D games in a 3D project
you need to be using the 2D Renderer and 2D lights
I am using the 2D renderer and lights, but that doesn't seem to work either
(fixed, ignore)
Hi everyone. I've often seen people say that transform.Translate is worse than rigidbody.velocity, because it doesn't work well with collisions. But when I turned on Auto Sync Transforms the collision started working perfectly. And since the vectors are not involved, transform is also easier to change. Well, the question is: is rigidbody better than transform, and in what way?
I was using the unity tutorials but they are using an older version is there any tutorials with the current version
Tutorials in unity 2018 and 2019 should work fine, it hasnโt changed so much
Unless it is a specific feature that had huge changes, what tutorials are you searching for?
They show the tile section and the newer version didnt have it
Which title section?
Ahh, tile
On which part?
What do you mean, where is it supposed to be?
In unity 2020.2 you go create>2D>tile
For tilemap you right click on the hierarchy 2D>tilemap>rectangular
I dont have tile
On where?
create 2d
Which version of unity are you using? Is it a 2D project?
2.2.7 and I though I did
You mean 2020.2.7?
yea, sorry
On the top part go to window>package manager>in project and check it has 2d Tilemap installed
I do
Hierarchy: Create>2D> tilemap appears?
I do have that
Go to window>2D>tile palette
yea that works
Why?
Some how there is something already in there
Show me a screenshot
Then there are the tiles already created, what is the problem?
Do you want to add more?
Is that a downloaded project?
I problem is they took out tile in the newest verision
Does anyone know the math Iโd need to make a UI sprite that hovers over the mouse on one canvas also work the same for another display of a different size? None of the ways Iโve tried so far have kept it to the same ratio, like if display 2 is half the size of display 1 the icon on display 2 isnโt at 1/4 across when itโs 1/4 across on display 1
Hi, how can i set the main camera to stop when reaching the tilemap edges?
I'm using Vector2.MoveTowards to make a sprite move/follow another, how do I figure out if the sprite is moving left, right, up or down?
I'm not sure how these two things are related
are you trying to figure out if you're moving left/right/up/ or down, or are you trying to find the nearest object?
My bad, got it solved tho. Tried to find out the direction of where my object was moving.
alright
https://i.imgur.com/9ncAVQh.png
public ParticleSystem psBlood;
Instantiate(psBlood, target.GetComponent<Transform>());
How come this doesn't instantiate it?
(not even in the editor)
Not getting any errors
you're sure the code is running?
Yeah
if(enemy.getHealth() <= 0)
{
ParticleSystem ps = Instantiate(psBlood, target.GetComponent<Transform>());
ps.Play();
GameObject.Destroy(target);
target = null;
}
The object gets destroyed properly after
Tried the play part since it didn't work at first but then noticed it wasn't even spawned in the editor
but you just... destroy the object
Yes, the target. Not the particle system?
you instance it and immediately destroy it because it's the child of what you destroy
How do I spawn it on that position without parenting?
You're basically saying "Here hold this baby", and then throwing the person and the baby off the cliff together
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation);
if (Input.GetAxis("Horizontal"))
{
rb.velocity = new Vector2(MovementSpeed, 0f);
}``` it says "Assets\Scripts\Controller.cs(23,13): error CS0029: Cannot implicitly convert type 'float' to 'bool'", on the if statement
oh, how do I fix that?
You ever try to write if (-1)?
Depends on what you want to do
Probably compare that value to something
Why is my layerMask not working (wrt to Raycasts). I'm using it to detect if the player is in the line of sight of the enemy, but the raycast is colliding with the enemy even though the enemy's layer (default) is not included in the layerMask ```cs
public bool CheckLineOfSight(Transform body1, Transform body2)
{
RaycastHit2D hit = Physics2D.Raycast(body1.position, body2.position, layerMask);
if (hit.collider == null)
{
return false;
}
Debug.Log(hit.collider.gameObject.name);
if (!hit.collider.gameObject.CompareTag("Player"))
{
return false;
}
return true;
}
Hi, how can i set the main camera to stop when reaching the tilemap edges?
I've gotten quite confused, I have one script trying to import basic pathfinding. That script has this variable: https://i.imgur.com/1a9jp8f.png (a public transform)
How do I go about setting that variable from another script?
The other script (on the same gameobject) looks like this: https://i.imgur.com/8dTb63b.png
It's the Target I want to change
Scripts can be instanced in the scene in your editor. They can also be given references to other script instances in the editor. Thatโs probably the most direct method if you only need one instance of each script, though there are a million ways to do this.
Every object (characters) will have this script running as to use the pathfinding.
But I'm not sure how I can set the target from another script on the same gameobject.
Lol, must've been drunk! Tried that before but now after a break I managed to get it on the first attempt. ๐
Thanks
Hi! How can I know what is the position in world space of a point inside a local UI object?
e.g. I have a scrolling list inside a hierarchy and now I have a calculated point inside that list, but I donโt know how to get the world space of that point since it is not a Game Object with a Transform but just a Vector2 :).
Thanks for the help!
I think Camera.ScreenToWorldPoint works for RectTransform and UI position
Raycast2D expects a position and a direction. You're giving it two positions.
It's going to interpret that second position as a direction
is there a way to make a BoxCollider2D snap to its new size/position immediately during an animation rather than morphing in between key frames?
yeah just make your handles vertical
ah, thank you! I completely missed the curves menu, I'm really new to unity animation
Im trying to make a game object follow my player and remain slightly behind it, and im kinda stumped on how i can have the object move behind the player as it turns
This is where im at at the moment
set its location when pressing direction keys
thats what im trying to do, ive thought of having a child object that it follows, so when the player sprite flips it will move towards it
your not showing how you have it set up just a video so I assume you are using void update to constantly follow player with and off set just check if A and D and set the offset to the correct side
you should just set it up to be a child of the player that way it always follows without needing a script to update follow then just check when A or D is press then set the child local location to +1 or -1 depending on what you are pressing.
transform.SetParent(newParent); then when D is press transform.localPosition = new Vector3(0, 0, -1); or 1 for other side
ive got it perfect ๐
nice
i wanted it to be smooth, and not too snappy, so i took a camera follow script and adjusted it a bit
Hello ! I can't stop my spawner from drawing "lines", and blocking my objects, at the maxY height. Like here (below the red line):
Actually, what I want to do is a spawner like this (in a loop of course). I specify that I have placed my objects manually:
A spawner with objects not too far or too tight, the one in the video is very good but I can't get a similar result ๐ฆ
You probably have a clamp function, or a if(y>height) statement somewhere
That would result in that kind of line
So without seeing your code, all I can recommend is to generate a value that is directly between your max and min heights.
@still tendon
is there any way i can prevent an object from moving too far away from the player?
i have an object that can follow the mouse, but i want it to stay within bounds of the player
How do I make the game a pixel type of thing, like tilesets and pixelated units
@brittle summit Just place pixel art into the game objects and you are good to go.
But there are also guides for this all over youtube, some are pinned in the 2D art channel
I am trying to use Unity Sprite Shape and I need to add points using a script. I have been searching documentation and forums but nothing is relevent. I need to have a point places every "x" seconds on the sprite shape. Is there any way to do this? I am using Unity 2019.4 | 2D mode
2d mode vs 3d mode is actually only a camera setting, so they function very much the same, but have sadly never used sprite shape, can do a quick google
Seems like most people don't add points using a script though...do you have to do that because of the level generation you have made or something? @limber tartan
I have a flower that is growing and it can move left and right, and behind it I want a curvy stem, that when the player moves, curves that way too.
That is why I need a point every x seconds, so that the stem curves
you could potentially move a point every second, seems like creating one will be quite heavy...but lets see if it's possible
๐ง That is an interesting idea
Sorry for all these questions, but can you move a point up if it is lower that the player by 20 blocks?
https://www.reddit.com/r/Unity2D/comments/brvbfy/can_you_edit_the_spline_of_a_sprite_shape_via_a/
This one show an example how you can edit the spline in a script, even added a gif of it.
1 vote and 4 comments so far on Reddit
Oh, unity also has a whole tutorial for how to work with sprite shapes
I've seen that one, but that causes issuses where the spline is like 2 pixels tall and you can barely see it.
in my implimentation
Might it be because you failed to set some settings for certain nodes maybe?
yep, sleeping on it is most of the time the best action :p
Oh OK, thx m8
Hi everyone. I've often seen people say that transform.Translate is worse than rigidbody.velocity, because it doesn't work well with collisions. But when I turned on Auto Sync Transforms the collision started working perfectly. And since the vectors are not involved, transform is also easier to change. Well, the question is: is rigidbody better than transform, and in what way?
You will simply not get realistic collisions when moving the transform directly. You will only get depenetration forces
Your object will not be stopped by colliders
Unless it's moving quite slowly and the depenetration pushes it out
Not sure what you're talking about with vectors, as you use vectors for modifying the transform just as you do with modifying a rigidbody velocity
They are also not very complicated
I wanna add a Attack Combo in the air while jumping but i dont know where to begin and this is my ground attack combo
is this channel also for Bolt?
@limber thistle Oh sorry, here is the code: https://paste.myst.rs/gxkpi15d
a powerful website for storing and sharing text and code snippets. completely free and open source.
How can I make that a Text Mesh Pro follows a 2d object ?
i think you can just parent the 2d object to the text mesh pro object and when the 2d object moves the text should move with it. otherwise IDK
thanks
If i'm using rb.velocity, i can't change it freely. For example, i want to have some acceleration in my movement and speed barrier too, and i'm using this code:
private float cap = Mathf.Max(maxSpeed, Mathf.Abs(rb.velocity.x) - 0.1f);
rb.velocity.x = new Vector2 (Mathf.Clamp(rb.velocity.x + direction * walkAcceleration, -cap, cap), rb.velocity.y);
And it isn't working, for some reason.
Heya, could use some tips!
Style 2d topdown.
So i'm using new input system.
and i rotate the character based on the movement.
However, the update is so fast, that when i release it register a few quick frames of input
which causes the top down character to quickly slide towards the last recorded input.
and the rotation to reset.
any tips how to combat this?
Thanks!
Your logic is flawed if you're trying to cap the velocity with that.
Maybe share short video of what you mean and your code?
It's noting major, just the basic code. but i try to get wasd and controller to work well, controller does good, wasd is the issue
Are you using Input.GetAxis by chance?
No sorry, im using the new input system
Line up your camera beforehand by using the camera preview in scene view
where is the camera preview
Could just be that when you release one button slightly before the other one, only the last button to be released is registered for a frame or two
click on camera
In scene view. Make sure Gizmos are turned on and you select your camera
ok
Yes that's what im getting to aswell, and try to fight that somehow xD
if your camera clipping planes near is too high and your objects are with in that range your camera will just clip though them you wont see them
Don't change clipping
Just look at the z position
Of your camera and your object
its 5 right now
Make sure they're not the same
.3 near and 1000 for far
Your camera usually should be at z -10 and your objects should be at z 0
means you will see as close up as .3 away from camera and as far as 1000 units away
For a typical 2d game
oh yea forgot we are in 2d xD
eyy pog it worked
Time.deltaTime is unecessary for AddFOrce inside FIxedUpdate
other than that it should work
oh wait
you're also missing this @main shuttle
void Start() {
rb = GetComponent<Rigidbody>();
}```
such as?
You forgot the {
where do I put it
i dont get the error code but its still dosent work
my "player" dosent move
did you attach this script to your player?
yes
Does your player have a Rigidbody?
yes
no
this is 2D isn't it?
yes
just rigidbody
why
2D physics should use Physics2D
Rigidbody2D
If this is a 2D game, with a 2D camera
your object right now is moving along the z axis
which will not be a visdible motion
yeah
remove the BoxCollider
you want a BoxCollider2D
you need to use all the 2D physics stuff for a 2D game
the rigid body wount go in the script now tho
right
because you need to change your variable
Rigidbody2D rb;
GetComponent<Rigidbody2D>()
I did
that code does not compile
rb.AddForce only takes 2 parameters
for a 2D rigidbody
fix your compile error first
actually it only takes Vector2
so you need like rb.AddForce(new Vector2(forwardForce, 0));
on once per frame or on start?
vecter 2 is missing a directive or an assemby reference
Did you spell it correctly?
ok its fixed
but its says the name fowardforce does not exist in the curent ccontext
did you capitalize it correctly?
It must match your variable name
forwardforce is not the same as forwardForce
yea it looks good I think
but its says no overload for method add force takes 3 arguments
correct
we're only using 1 argument
the Vector2
you muyst have misplaced a parenthesis or comma
try to copy what I have exactly
I did
show it?
ok i got it in the script
Can u explain what a vector does exatcly so I can learn it
It's just a thing that holds an x value and a y value
in this case, we're using it to tell the rigidbody in what direction we want to add a force
we're using 2000 in the x direction
0 in the y direction
Vector3 is for 3 dimensions and is the same except it also has a z in addition to y and x
how does it know that its x not y
Because we used the constructor: new Vector2(forwardForce, 0)
the first parameter is always x
the second is always y
oh like a graph
yes
thanks alot
https://gyazo.com/4432565cb43d1beb8c333bf5a4d33ffc I'm not sure if I'm meant to ask this here cause its not really a question of exact code; more of a "how would one...". So I'm trying to make the flashlight effect stop when it hits walls, but as you can see it goes through them, right now its a sprite mask system and the tutorials I've found on youtube use raycast & meshes but collisions for me are broken on those, any ideas?
(the wall jump thing is also a bug but I'm not as concerned about that rn)
Unity has a 2D light system
which includes shadow support
you will have to give all of your obstacles ShadowCasters or what have you
oh thanks
Hi guys, I need a quick question answered if its not much trouble... Can I make 2d "meshes"? instead of sprites make like polygons like the sprite editor but with the option to make holes... I don't know if I'm explaining myself properly..
Just make images with transparent sections
But I'd like to zoom in and out without changes in quality
I intend to use solid colors, no textures
that's a whole different subject
but look into vector art
Unity has a Vector Graphics package https://docs.unity3d.com/Packages/com.unity.vectorgraphics@2.0/manual/index.html
but it's still in preview
so use it at your own risk
Like this
Yes I understand
I might aswell make a flat 3d model...
You would use something like Inkscape or Adoibe Illustrator to create SVG files
You can also make flat 3D models yes
Oh I gave it a read a few days ago
I plan to use the physics engine on this project, so I'll see which one is better suited for that job
Thanks
You can use 2D or 3D physics either way
You can use 2D physics with 3D meshes and vice versa
rendering and physics are completely separate things
In terms of performance?
Oh thats great to know
I don't think they're that different performance wise
I would imagine that the 2D engine might be faster but I can't say that for sure
It'll probably calculate an extra vector which will be 1 anyways
I think the svg importer is the way to go, thanks!
it has freeze rotation settings
If you use rn.MoveRotation and not transform.rotation
Try rb.MoveRotation(angle); instead of rb.rotation = angle;
is it possible to detect what type of ground surface the player is standing on with raycasting?
@orchid pewter yes
using layers or different methods?
Layers, tags, comparing materials, many different methods
oh i should use both layers and tags
I dont see any particular reason to do that but sure if your implementation calls for it
the raycasting would detect if the player is on the ground and also detect the surface type by tags?
I have an issue... So I have a circle sprite and a ground (The ground I made larger on x and z) both have box colliders 2d but, when the ball falls it bounces in one spot (and does not go through) But any other spot it does go through? Anybody know why?
its probably really simple, but how can i add the players x and y coordinates to a value?
is it just + player.transform.position.x
*Water.cs, I think there is a collider for the circle, did you add bounciness to your circle sprite. To add bounciness, right click to projectโs asset folder then create>physical material. Name it bouncy or anything haha then change the bounciness to 1.?
@plain pier *Water.cs, I think there is a collider for the circle, did you add bounciness to your circle sprite. To add bounciness, right click to projectโs asset folder then create>physical material. Name it bouncy or anything haha then change the bounciness to 1.?
Sorry to bother, but everytime i create image with a button component it doesn't work, anyone knows how to solve this?
make the button component and change the sprite of the button component itself. that should work
I have a question about unity 2D.
How do I set a specific width and height to a gameObject?
I am getting a distance between two objects and I need to set a circle around the player with the same radius (or with the same units of measurement).
How can I do that?
best to start with an object with exactly 1 radius for example
then it is very easy to scale
How can I set circle radius 1? Then that would be a rectangle. @snow willow
A circle with radius 1 is a rectangle?
One what? One pixel?
Where can you change unity world space unit? Or just see it?
Is this a sprite?
Yes
If pixels per unit is 100
then a 100 px width image is 1 unit wide
so you can either change the size of the image in image editing software, or adjust that pixels per unit setting
until your circle is 1 unit
in diameter I guess
And the distance between two objects is in units? (Vector3.distance)
yes
Thank you so much!!!
Ok Thank You Very much!
Hey guys, I need help with mobile input system, basically when I move on my joystick controller my character also shoots at that position, i want to set it so i can tap on screen anywhere in the scene and shoot there, can someone help me with this who's not too busy?
Just one thing..., It wont let me put the material on the circle...?
Oh it worked
Ty
@plain pier I am a week or so in unity, I am glad it helped you๐.
void Update()
{
if(Input.GetKey(KeyCode.Space)){
//do something
//wait like 2 seconds
//do something after
}
}
How do I wait in this?
use a coroutine
void Update()
{
if(Input.GetKey(KeyCode.Space)){
StartCoroutine(WaitThenDoSomething());
}
}
IEnumerator WaitThenDoSomething() {
yield return new WaitForSeconds(2f);
// Do the thing here
}
You will also need using System.Collections; at the top of your file.
ok
otherwise you will be doing the thing for every frame the key is pressed
lol
Vector3Int cellPosition = Tilemap.WorldToCell(transform.position);
transform.position = Tilemap.GetCellCenterWorld.(Vector3Int(0,0,0));```
hello i'm trying to get my "character" to use grid movement but i can't make it work. i was wondering if someone have an idea about this or what i'm doing wrong
Tilemap.GetCellCenterWorld.(Vector3Int(0,0,0));
Something's missing here
Tilemap.GetCellCenterWorld().(Vector3Int(0,0,0)); maybe?
also
Can anyone tell me why my character seems like they're "stuttering"?
It look like the character doesn't have vsync.
Here's my code if that means anything:
float horizontal;
float vertical;
float moveLimiter = 0.7f;
public float runSpeed = 20.0f;
void Start()
{
body = GetComponent<Rigidbody2D>();
}
void Update()
{
// Gives a value between -1 and 1
horizontal = Input.GetAxisRaw("Horizontal"); // -1 is left
vertical = Input.GetAxisRaw("Vertical"); // -1 is down
}
void FixedUpdate()
{
if (horizontal != 0 && vertical != 0) // Check for diagonal movement
{
// limit movement speed diagonally, so you move at 70% speed
horizontal *= moveLimiter;
vertical *= moveLimiter;
}
body.velocity = new Vector2(horizontal * runSpeed, vertical * runSpeed);
}```
Vector3Int(0,0,0) needs to be new Vector3Int(0,0,0)
This is fishy in FixedUpdate:
if (horizontal != 0 && vertical != 0) // Check for diagonal movement
{
// limit movement speed diagonally, so you move at 70% speed
horizontal *= moveLimiter;
vertical *= moveLimiter;
}```
what happens if you get two physics frames?
You will multiply horizontal by .7 twice
and vertical
you probably want to only modify a local copy
The other thing is
physics movement is naturally "stuttery"
unless you turn on rigidbody interpolation
because the physics update is not synced with the frame update
Even before implementing fixed update it did the stuttering.
I've turned on rigidbody interpolation aswell.
you'd have to share your code in whatever other state it was also stuttering in
but if you were using Rigidbody, that moves in sync with FixedUpdate no matter what
interpolation should fix it though
i already try this same error
It is one of your errors
you have many
scroll up I mentioned another one
above the giant code block
i know i saw it
someone. i already try the new(new Vector3Int(0,0,0));
and i add the () to the other line too
show your new code, show what your errors are
I don't even remember what other things I did, I've tried a load of different movement techniques and the stutter remains, even in some of my other projects.
Is there a better way to move the character in all directions?
I'm still new to this, so I'm sorry if I'm not understanding
And maybe break that line of code up into multiple lines so it's easier to find and fix the errors
it's with the code but here again https://cdn.discordapp.com/attachments/763500535554375750/820129365378596953/unknown.png
sure sec
(use https://paste.myst.rs/)
a powerful website for storing and sharing text and code snippets. completely free and open source.
Grid Tilemap = transform.parent.GetComponent<Grid>();
Vector3Int cellPosition = Tilemap.WorldToCell(transform.position);
transform.position = Tilemap.GetCellCenterWorld().(new Vector3Int(0,0,0));```
this is not right
You got a Grid object
and you're trying to call functions on it like it's a Tilemap
just because you named it "Tilemap" doesn't make it a Tilemap object
What is a "Grid"
is that a custom class you made?
WHy aren't you just using the map variable you have already defined
that is a Tilemap
then finally the way you are calling GetCellCenterWorld().(new Vector3Int(0,0,0)); is wrong
it should be GetCellCenterWorld(new Vector3Int(0,0,0));
you told me to try this way
I was telling you that to fix one error you had
which was the missing parentheses
Just becuase I didn't also fix your other error doesn't make it wrong
basically the dot you had was super confusing
and about the grid im really new on unity so im trying to figure it out. just wondring if i could get some help trying to fix that
You most likely just want to use map
void Start()
{
destination = transform.position;
mouseInput.Mouse.MouseClick.performed += _ => MouseClick();
Vector3Int cellPosition = map.WorldToCell(transform.position);
transform.position = map.GetCellCenterWorld(new Vector3Int(0,0,0));
}```
it's like i didnt add anything to it with that code
the 2 new lines Vector3Int cellPosition = map.WorldToCell(transform.position); transform.position = map.GetCellCenterWorld(new Vector3Int(0,0,0));
they are like commented. they added nothing to the script
not sure what you mean
I mean it's true that Vector3Int cellPosition = map.WorldToCell(transform.position); won't do anything
you're just reading a value out to a variable and then ignoring it
https://docs.unity3d.com/ScriptReference/Grid.GetCellCenterWorld.html this is where i got it from
Ok
But you have a Tilemap
which inherits from GridLayout
You already have your Tilemap reference
why do you need a separate Grid reference?
It's the same object, with the same method
in any case - what are you actually trying to do?
snap the character to the grid. so only move inside the grid
ok and how are these 2 lines in start supposed to do that?
Start only runs once
You'd need to make a change inside MouseClick()
to snap the mouse position to the grid
ty for the info i will try to find out something about this
im trying to make a main menu but i get the error cs0103 scenemanager does not exist
Did you capitalize it properly? SceneManager
And do you have using UnityEngine.SceneManagement; in your file?
I am doing a clicker, why clicks are not counted, I think this is due to an error in the script. Who can help solve the problem please write to me
how do you delete objects?
How can you make the grass sprite go over the background instead of being behind it?
Nevermind, already figured out. I changed the sprite's Z position to -0.01
anyone here
Have a question:
After performing a raycast, if it hits an object then i find the hit.distance and assign it to the objects velocity.x
It makes the object transfer to that position immediately. That how i do kinematic collision checks. But when i Debug.Log(hit.distance) it returns a value between the origin point of the raycast and the collision point.
then what does actually gets assigned to the velocity? is it a vector? what is it?
I have a question about unity 2D.
For some reason button command is not working.
And the weirdest part is that the Debug.Log is happening, but everything else isn't.
Does anybody know why is that?
Well if itโs showing the log then itโs executing the function, unless you have another log that logs โy.โ So what is it not doing that you want it to do?
It is not changing the variable and not destroying the object. I tried putting in some other functions too, but only Debug.Log is executing.
what other functions?
For example changing other variables.
But only thing that is happening is the Debug.Log @spring adder
where is the option to import my sprite
I cant find it
someone just please
tell me where it is
Just drag your sprites from file explorer into unity
hey guys i'm trying to make an enemy move from a point to another but can't seem to make it work
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveSide : MonoBehaviour
{
public float speed;
public bool MoveRight;
// Use this for initialization
void Update()
{
// Use this for initialization
if (MoveRight)
{
transform.Translate(2 * Time.deltaTime * speed, 0, 0);
}
else
{
transform.Translate(-2 * Time.deltaTime * speed, 0, );
}
}
private void OnTriggerEnter2D(Collider2D trig)
{
if (trig.gameObject.CompareTag("turn"))
{
if (MoveRight)
{
MoveRight = true;
}
else
{
MoveRight = false;
}
}
}
}
this is the code i used, it can go back when it reaches one bound but then when it reaches the left one it just goes trough the collider without triggering
When you are in the sprite editor there is an option slice. Push that.
it still has the massive border but there is only one sprite
You also need to choose multiple as a sprite mode.
???
Someone know how to make a script on a 2D isometric map
Like that ?
With movement point
You'll need a pathfinding algorithm
But to do that and get the visual effect too will require a lot of work
I'm betting that's 3D anyway, just shown as 2D iso
I want to start learning 2d coding. Where I should start and is unity free?
Yes unity is free
Some of YouTube video are really good to start
You can't easily find cool free assets
Can *
Ok thx
I am very new to shaders, just wondering how I make glowy objects. Essentially, the additive blending thing. I have this much so far
can someone help me making a 2D terrain randomly generated than can be destroyed?
I have a question about unity 2D.
Can you change scriptable object properties through script?
yes
Ok, thank you
hi guys, how to start making a game like worms? the worms with bazooka
I have a question about unity 2D.
What is the toString() format, so if there is a number smaller then 10, it is going to put a zero before it. (For example 01, 02, 03, 04 ... 10, 11 12)
Does anybody know this???
It's all documented there
It's also a C# question which isn't really related to Unity FYI
I am trying to use "D2", but is throes an error: The specified format 'D2' is invalid.
How are you calling it
string.Format("0:{0}", objectShower.timeLeft.ToString("D2"));
It is a float
You have to use the float specifiers then
Ok, thank you! (I will just make it int)
Er fixed point I guess it's called
Anyone know how to rewrite: if (Input.GetKeyDown(KeyCode.UpArrow) && transform.position.y < maxY). to Input.GetButtonDown?
Input.GetKeyDown("w")
Does someone here know how trails works?
Is there a way I can make a game that toggles a camera to view all sprites as either pixelated or with a bilinear filter?
You have to register the button you want in the Input Manager (it might already be registered as "up" or "forward" or something, not sure).
Hm. I have some questions regarding a 2D platformer game Iโm trying to make for Uni, but Iโm not at my computer at the moment
But one of them is like...
How would I be able to adapt the Brackeys 2D character controller to create a character that moves around by rolling like a ball?
... except the character in this case is more a box than a ball, but still
I have a question about a movement script.
When i playtest my scene, i enabled debug.log, the console is displaying the numbers, but the character isn't moving at all.
Reversing the scale of stuff causes all kinds of issues like that so I'd usually not recommend it
If you're using a SpriteRenderer there's a "Flip X" option or whatever to reverse the image
i have a sprite with a animation how can i switch between frames using code and a int
show code
implement character movement by changing velocity of rigidbody, dont use transform.translate
ie
public class PlayerController : MonoBehaviour
{
Rigidbody rb;
public float speed = 1.0f;
Vector3 movement = new Vector3();
private void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
rb.velocity = new Vector3(movement.x, movement.y, 0);
}
void GetInput(float speed)
{
// setting input variables
movement.x = Input.GetAxisRaw("Horizontal") * speed;
movement.y = Input.GetAxisRaw("Vertical") * speed;
}
}
switch between frames? animation clip should contain all frames for that clip and play them automatically
ie
unless your question is how to transition between animation clips using code and a int
ok i have 3 of the same sprite on a animation
i need to switch between them
is a animation a good way to do i
t
show animator window
ok
how do you import unity stuff into roblox
which channels? sorry
ok so you have 3 key frames, are they all part of the same animation?
yes
does the animation play when you enter game mode?
yes
why would you need to switch between them
its a where is waldo type of game where u need to find the right collor one
can u show what the sprite of each keyframe is
.
whitout the white bg
what conditions for the int would you want the sprites to switch
0 1 2
how would you want the sprites to switch
any way
why would you need 0 1 2 to switch between sprites
how do you want to change the sprite in runtime
ok thats the answer im looking for
animation would not be ideal way to implement that
um can i ask or am i barging in
https://stackoverflow.com/questions/66624074/when-character-flips-fire-point-does-not-rotate-2d the question
if you want to change the sprite on click, create script on the gameobject, declare a sprite array and create a function where you assign an int variable a random number between 0-2 for index of sprite array, then assign sprite renderer the sprite array[index]. reference this method on click
public Sprite image0;
public Sprite image1;
public Sprite image2;
public Sprite[] imageList = new Sprite[] {
image0,
image1,
image2,
...
};
```?
i wouldnt declare a sprite object for each image
just the array
you can set size and initialize the array in the inspector
what you mean by fire point?
the point where the bullet spawns
when i face right it spawns and goes right
which is what i want
but
when i face left it spawns and goes right
i want it so when i rotate my sprite
i also rotate the fir epoint
i already rotate the sprite and the gun
dont know how to rotate the point
is the fire point a child of the object which runs the script to flip the player
nvm
?
change the velocity of the bullet to negative when left input is detected
what
or