#๐ผ๏ธโ2d-tools
1 messages ยท Page 39 of 1
goldText.text = $"Gold Coins: {data.gold / 1000}K";
correct
Noice
Thanks guys
This saved me from spending an evening figuring this out
Umh, I might wanna show one decimal tho
If it's not too much, like how to change it to show 1.1k 1.2k
make it a decimal instead of an int
then look up how to round with Math() or something else
in C#
(data.gold / 1000).ToString("0.0")
if gold is switched back to a double or decimal
hi guys I'm currently facing a problem. I'm trying to make a dash for my character but it's in conflict with the movement script
whenever Dash() is executed, it doesn't do anything because the velocity x is used by the movement
is there a workaround for this?
why the player when touch food object rotating https://paste.myst.rs/o3j2105w
a powerful website for storing and sharing text and code snippets. completely free and open source.
this is 2d, right?
can i have a screenshoot of your rigidbody2D set up?
I'd do a boolean isDashing, and if the Dash btn is pressed, call the code in fizedUpdate, else, use the one you already have (movement)
ohh thank you. I went the other route by having the movement being transform instead of velocity and have velocity as the dash haha
for some reason i can't get 2d raycast to work, it just ignores colliders
can you please Debug.log(hit.collider.name); after your first line?
If you get only nulls, (and you believe it should be working), debug draw the raycast to see how it actually looks. You can use Gizmos.drawline for that.
If the line actually shows that you hit the collider, your issue is with layers or physics.layer collision settings
if the line is wrong, you setup the raycast wrong
huh, there's something wrong with the references or something in the raycast line
it is a long code? could youshare?
mean it didnt collide
Satiris' option is good to see where are you shooting your ray
i checked it before and it shoots in a needed length and direction
can you put the debug line after the "if" and remove the comparteTag wall? and show me
god dammit, why does the solution always needs to be so painfully simple
ughh the wall object was just on -8 on z axis
now it works
@narrow jacinth Don't post off-topic media
gtk
oh hello another quick question. How do I access non static variables from a different script in my project?
Ik there's t he GetComponent thing but I don't really understand the namespace
you can, [SerializeField] ScriptName scriptName assign it in the editor, and then access it:
scriptName.VariableName, assuming the VariableName variable is public.
the second scriptName I can name it anything right
ScriptName is my actual script name
I'm assuming
ScriptName is the actual script name, like Player
ah got it
scriptName can be anything, but it's good to name it the same, I guess
also what does SerializeField do
ohh gotcha
I put this under Start() and it's giving me error that I need a bracket?
the SerializeField can't be in the void start it needs to be above it
what I did instead of searializeField is using public
show whole class
what is playerMovement ? is it a gameObject a script something else ?
Nice XD
why's coding so hard
idk I'm still trying to make multiplayer work well but I keep finding problems
I
I got another problem
I'm using velocity to make my character walk
whenever the D or A key is pressed
I'm also using velocity to make the character dash
but the two velocities conflict with each other, so I made it whenever J is pressed, the velocity movement isn't used
but there's a really big delay for when that happens so my dash isn't instant
anyone know how i can solve this
i have a quick question, if my object is rotated 90 degrees (to the left) ho i make it move to his local Y position + 3 game units so the object will fly to the front of where it is aiming, im currently using this:
target = new Vector2(transform.localPosition.x, transform.localPosition.y + 3);
}
void Update(){
transform.position = Vector2.MoveTowards(transform.position, target, speed * Time.deltaTime);
if(transform.position.x == target.x && transform.position.y == target.y){
DestroyProjectile();
}
}```
but what seems to happen is that the object i want to move is just flying upwards while his target is the left because the object that instantiated it made it point the left
transform.position += transform.up * 3; would move 3 units in the direction that its local y is pointing
thanks bro
wait
i tested it and is not what i want
i want it to increase his local Y position
each frame
then multiply it by Time.deltaTime
ok
if you actually want it to move in local space then transform.localPosition += new Vector3(0, 3 * Time.deltaTime, 0);
it works thank you
Please help me find mistake on code
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public GameObject PlayerPrefab;
public GameObject GameCanvas;
public GameObject SceneCamera;
private void Awake()
{
GameCanvas.SetActive(true);
}
public void SpawnPlayer()
{
float randomValue = Random.Range(-2f, 2f);
PhotonNetwork.Instantiate(this.PlayerPrefab.name, new Vector2(this.transform.position.x * randomValue, this.transform.position.y), Quaternion.identity, 0);
GameCanvas.SetActive(false);
}
}``````
This random thing spawns that falls into nothingness.
I have a question
where can I find a source that can teach me how add movement to my character? (wasd)
Do you just intentionally ignore responses?
#๐ปโcode-beginner message
no
I couldn't find what I wanted
on youtube
Well nobody here is going to be your personal secretary until you find what you want.
There are countless tutorials on the internet to handle movement.
Any one of them would be more than enough. Saying that none of them suit your needs is just ignorant.
alr thanks
If you have specific questions regarding implementation of them, after the fact, then you're welcome to ask for help.
But at least make an effort.
Hey, does anyone know how to make it so that the player character only does something each time you push a button, and it doesn't repeat as long as you hold the button down?
//code here
}```
Okay, thanks!
np
Hi, I have a question, how to make 2d randomly generated world with tilemaps on different layers, or if it's not possible on 1 layer?
i've made a procedural generator using cellular automata
there's a lot of ways you can do it, a lot of algorithms to use
after having the logic you'll just make a script to loop through your generated map and put it in the tilemap
here's how i did it
maybe it will be helpful to you
the way it works: firstly it generates a random "noise", then it fills the close noises and remove the distant ones, expand it, detect rooms and connect in a way all of them are connected
and the end result
also it can generate using a seed, this way the map generation would be the same if the seed is the same
Thank you so much, that exactly what I was looking for 
hey i need a code with a charactercontroller 2d for an endless runner and i need an automatic Map generator
Get writing!
This discord isn't the place to ask for free work.
and what is this?
Someone generously sharing their work
i can do all and let me ask!
using System.Collections.Generic;
using UnityEngine;
public class NoteScorer : MonoBehaviour
{
private int playerScore;
public int perfect = 5, great = 3, almost = 1, miss = 0;
public int CalculateScore(float noteScore)
{
if (noteScore > -.4f)
{
Debug.Log("Almost");
playerScore = almost;
}
else if (noteScore > -.2f)
{
Debug.Log("Great");
playerScore = great;
}
else
{
Debug.Log("Perfect");
playerScore = perfect;
}
return playerScore;
}
}```
My ddr game keeps calculating scores as almost than the other scores. I don't know why
The notes are moving sideways
Debug the noteScore value coming into CalculateScore to see what it's giving you.
Also, you probably want to do do playerScore += almost; so that your variable accumulates.
Should I do += for great as well?
And the CalculateScore is part of the activator script so the activator knows when it collides with the note, calculating the input as the given score
if the score is greater than -0.4, it is always greater than -0.2. The "Great" part will never run
"Perfect" will run only if the score is less than or equal to -0.4 with this code
I should switch the values then?
do you think that would help?
can you express in english first what you want to do?
that might help with writing the code
I want the code to essentially show a score when a note is destroyed by the activator. Depending on how close the note is to the center of the activator, I want it to show whether the button input was almost, great, perfect or a miss
yes but
let's get into the details of the score analysis
you have a number right?
What's the valid range of that number
seems like it can at least be negative?
is it like -1 to 0?
The activator has an x position of -19. I want the note to print a score whether it is dead center to it or close. I tried implementing values that are close and went from there, but it still prints as almost
ok be precise though
this is code we're talking about
something like
"If it is less than -1, it's a miss"
"If it's closer than -1, but less then -4, it's an Almost"
etc..
if (noteScore < -24, it would be great)
using System.Collections.Generic;
using UnityEngine;
public class Activator : MonoBehaviour
{
public KeyCode key;
bool active = false;
GameObject Note;
private float arrowLocation, activatorLocation;
private float noteScore;
public int playerOneScore;
public int playerNumber, damageToDeal;
public bool playerOneHit;
public DamageScript damageScript;
public NoteScorer noteScorer;
// Start is called before the first frame update
void Start()
{
activatorLocation = this.transform.position.x;
//Debug.Log(this.name);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(key) && active)
{
arrowLocation = Note.transform.position.x;
Destroy(Note);
noteScore = Mathf.Abs(activatorLocation - arrowLocation);
if(playerNumber == 1)
{
damageScript.playerOneDamage = true;
damageScript.playerOneScore = noteScorer.CalculateScore(noteScore);
}
//Debug.Log("Player One did " + playerOneScore + " damage");
}
}
void OnTriggerEnter2D (Collider2D col)
{
active = true;
if (col.gameObject.tag == "Note")
Note = col.gameObject;
}
void OnTriggerExit2D(Collider2D col)
{
active = false;
}
}
As a reference, this is the activator code that calls the NoteScorer
Piskel is good
ok thx
at least seems good to an amateur like me ;D
well...
Ok i have a nooby question coming in. It's basically my first day of unity but I can't figure this out.
me too ๐
This is about the 2D physics engine. I have gravity set to the default, -9.81, and a rigidbody with a mass of 1. When I apply a force of 9.81N upwards, the block moves upwards even though the net force should be 0. Can anyone explain why this is or if i'm just doing something stupid?
From where are you applying the force?
In Update?
FixedUpdate?
yeah in void Update()
Use FixedUpdate for physics
how to get the animation to unity?
the game engine applies gravity once every FixedUpdate
Oh I see
probably a way to export the spritesheet from piskel
I'm never tried it personally
That works for me. Thanks so much
Tried multiple methods, however, it will still come up as almost
i downloaded a png file but i cant add it to unity?
try checking for perfect first, then good, then almost.
Just drag it into the Assets folder
aaah got it
but i made an animation and now its just a photo how to make it an animation?
Sprite Animations are animation clips that are created for 2D assets. There are various ways to create Sprite Animations. One way is to create them from a Sprite Sheet, a collection of Sprites arranged in a grid. The Sprites are then compiled into an Animation Clip that will play each Sprite in order to create the animation, much like a flipbook...
it says : unaplied import setting
apply it ๐
but then it dissapears
what is the difference between sorting layer and order layer?
order in layer controls sorting within a single sorting layer
to be honest I haven't played with that stuff much
idk what people use it for
I could imagine something like - let's say a multiplayer game
all the "players" are on a certain layer
but your character is always sorted within that layer to draw on top of everyone else
so you can see yourself
that kinda thing I imagine
alr thanks for the help
soo how can i fix that?
i can screenshare
do you know what layers are?
yes
And do you know how to use them
but i want to animate a sprite
can you call me on discord?
yes
soo how can i make a pixel art not blurry ?
https://blogs.unity3d.com/2015/06/19/pixel-perfect-2d/ There's also pixel perfect package, it has some learning curve as well.
well that not solved my problem
.
@still tendon Why are you pinging me? You didn't post any problem. You asked about pixel art I pointed you to resources.
i just want to know how to unblurry something not 10 page of stuff
how to make it not blurry?
Sometimes the answer to your question doesn't fit into a single tweet
well i got it filter mode
how can u make your camera move with your character?
{{ description }}
help please
fore some reason the seconds "position" is marked as an error in visual studio but it should work
only Transform has position
can i get a script for moving in 2d?
@still tendon Yes, you can find one in many tutorials on Unity Learn. Links are pinned in #๐ปโcode-beginner top right.
i tried 5 script none of them are working
Have you tried learning from them?
well my character is falling with 20000km/h right now
Hi, this is probably an obvious question but I can't find a simple answer. I have 2 circle sprites in my 2d world and in one of my scripts I can select the rigidbody of the component its applied to, but how can i select another rigidbody in the scene?
Simplest way is like this:
(replacing Transform with Rigidbody obviously)
I'm not going insane right?
This should only become true when the box is coming in contact with an object on the "Walkable" Layer defined in the Inspector?
public LayerMask walkable;
public void GroundCheck()
{
isGrounded = Physics2D.OverlapBox(groundCheckPosition.position, new Vector2(box_X, box_Y), walkable);
}
Thanks, I'll give it a shot
Awesome, cheers.
Uh guys?
RaycastHit2D does not detect a hit if the target object slides into the ray?
{
proximity = Physics2D.Raycast(enemyCollider.bounds.center, transform.right, 12.5f, playerLayerMask);
return proximity.collider != null;
}```
My current code
it will be a problem with some combination of the parameters you're passing in and the setup of your scene
e.g. is the ray origin at the right place and in the right direction?
Are the objects in the right place to get hit by the ray and in the correct layers (and do they have colliders?)
Are you destroying one of the rigidbodies/objects
Did you Debug.Log to make sure the code is running
show code?
Sure
The object in question is an enemy gameObject that flips every 7 seconds.
the flip takes the ray with it.
if my player slides into the ray, no hit is detected
although if the enemy flips and then detects a player, a hit is detected
Enter:
if (trigger.gameObject.name == "triggerDetector")
{
Debug.Log("Enter");
triggerText.SetActive(true);
}
Exit:
if (trigger.gameObject.name == "triggerDetector")
{
Debug.Log("Exit");
triggerText.SetActive(false);
}
are you casting every frame or only when you flip?
the ray is not really something that can be "slid into"
it's just a query that happens immediately when you call it
so somethign is just not set up right
put a debug.log outside the iff statement
hmmm
Thanks for the tip
Where? Still inside the void, but just outside the if?
void is the return type of your method. But yes inside the method/function and outside the if
Ok
Hey turns out you're right and I'm gigantically dumb
Nothing happens
Had the check nested in flip()
Are you disabling one of the objects in question?
The text that shows up when you enter works, but when you exit the trigger, that text is supposed to go away. It worked before, but suddenly stopped
the text doesn't happen to be the same object that has the collider or a parent of it, does it?
No
OMG
I FOUND OUT WHY! The TriggerEnter is 2D, as it should be. The Exit, however, isn't!
I don't know how that happened, but. Huh
Noted!
lmao well thanks for your time
hi, i have a problem trying to instantiate a "prefab". And it is that after coding it I can see the correct behavior of the "prefab" in the scene, but in "game" nothing is seen. Can someone help me?
Does everything needs to be in the same public void Update() or can create more and they'll function as one in the same script?
if you have modifications to the gameObject in scene, in hierarchy and not in the prefabs
The prefab object and the in-scene object will work differently
If that is the issue, simply apply the modifications to the prefab by either opening the prefab or right clicking on modification/component-> apply
What would be the best way to find if my player is to the left of to the right of my player?
Thanks for answering, but no, that is not the problem, when I put the "prefab" in the scene manually, in the "Game" window I can see it without problems and when I give Play the "prefab" will move with the behavior that I have programmed. But those that are programmed in the Spawn are not instantiated on the screen,
but if I can see them behaving correctly in the scene screen. I divide into 2 seeing the same "Scene" and "Game" and in "Scene" everything works correctly, but in "Game" the "prefabs" are not instantiated.
Is instantiation of the prefab dependent on the gameObject present at start?
Did you give the right reference?
The reference for instantiation should be the prefab in your assets window
not the hierarchy window
Yes, the reference is taken from the folder where the prefabs are saved
Then i'm out of ideas dude, can't help ya
Any idea tho?
rb.AddForce(new Vector2(dash, 0), ForceMode2D.Force);
how do i make it go opposite way
-dash(minus dash)
@heavy gale thx
np
@blazing narwhal Don't cross-post.
ok, sorry mb
Why isnt my Character Moving? i used the Same Script and it used to work, now i added a different Sprite, made some Animations and when i wanted to use this Script he just wasnt moving
using UnityEngine;
public class BasicMovement : MonoBehaviour
{
public float MovementSpeed = 1;
private void Start()
{
}
private void Update()
{
var movement = Input.GetAxis("Horizontal");
transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed;
}
}
If you have an Animator on your character that can interfere with movement scripts like this
Try disabling the animator to see
its disabled
and?
ok is it working?
still nothing sadly
ok then your problem is not that
is your movement code running
use Debug.Log to find out
yeah one sec
then if it's running, check movement speed, check the input values, etc...
also do you have a CharacterController
or Rigidbody?
of course fix all compile errors first...
So I have a question, I am watching a tutorial video and the guy shows us how to make the bird that we are making fall, I know how to do this and I decided to try it by my self instead of watching that part and I used box colliders (2d) and rigid body, it didn't work so I watched the video and the tutorial guy used polygon collider instead of box collider because the bird it's an oval. What I don't understand is why doesn't the box collider work? Why do we especially need polygon colliders for ovals?
I hope you understood my question
Itโs hard to say without knowing how it didnโt work.
A collider diff is definitely not a problem, check layer interaction in edit->project settings
also this
the shape of the collider is just that - the shape of the collider
you can make it whatever shape you want
it didn't work in the box collider
what didn't work
instead it worked in the polygon
define "didn't work"
2d
Then the only difference is the shape
if it went through it would be because it was set as a trigger
or on a layer that didn't collide with ground
alr thanks for the help
Can anyone help me figure out why this is throwing an error?
'Collider2D[] hitColliders = Physics2D.OverlapCircle(Vector2 currentExplodePoint, float radius);
"syntax error ',' expected"
Collider2D[] hitColliders = Physics2D.OverlapCircle(currentExplodePoint, radius);
will give me a Cannot implicitly convert a UnityEngine.Collider2D to Collider2D[]
nevermind, the Google came thru;
https://answers.unity.com/questions/1261957/cannot-create-a-2d-collider-array.html
Physics2D.OverlapCircle only returns one Collider2D. That's why the error. Use OverlapCircleAll, which returns the desired array of Collider2Ds, which is probably what you intended to do
What is the difference between these 2 codes? and which one is better?
Vector3 newPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = new Vector3(newPosition.x, newPosition.y) ;
Vector2 newPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = newPosition ;
the first one doesn't compile The first one is kinda pointless
the second one is sensible
so the 2nd one is better?
definitely
it's shorter
easier to read
and probably faster too
since you don't have to call the Vector3 contructor
I have done a better code than the tutorial guy that I was watching ๐
Thanks for the help
freezing rotation on a square?
// Update is called once per frame
void Update()
{
Debug.Log(Circle.position);``` so im trying to debug.log the position of a circle thats moving but it gives an error "the variable circle of camerafollow has not been assigned"
camerafollow is the name of my script
Have you assigned a transform to Circle? It's literally telling you that's what you haven't done, if you read the error.
So, public means it can be reached from other scripts, right? So, I should be able to reach a function from one script, from inside a different one, right?
Generally speaking, yes.
So I don't get why I can't reference an IEnumerator from a different script. I've referenced variables before, but never a function, so I'm not too sure how it works
what happens when you try, and how are you trying to do it
keeping in mind that generally if you have a function that returns an IEnumerator it's probably a coroutine
Well yeah, it's a coroutine I'm trying to run from a different script. If x happens, run this coroutine
ok
so what happens when you do that
compile error? Runtime error? Nothing happens?
Are you just calling the function, or are you calling it with StartCoroutine?
I tried referencing it like a static variable, example:
ScriptName.FunctionName
That's how static variables are reached, but that's not happening with the coroutine
Well a coroutine is afunction
you call functions with ()
The ohnly time you really reference a function without the () is when you're doing delegates which is a more advanced topic
but beyond that
An object reference is required for the non-static field, method, or property 'FoodSpawn.RandomSpawn()' [Assembly-CSharp]csharp(CS0120)
Is what it says
it's a Coroutine and to call coroutines you need to use StartCoroutine()
Yeah
If it's not static you need an instance
same as it is with fields
StartCoroutine(FoodSpawn.RandomSpawn());
that only works if it's static though
otherwise you need an instance
e.g. public FoodSpawn foodSpawnInstance; < assign in inspector
StartCoroutine(foodSpawnInstance.RandomSpawn());
Ohh
so basically the only difference between a field and a method is you call methods with () or (parameter1, parameter2)
the rules for accessing them are the same
Alright, thanks for the help
I can't get triggers to work on anything right now. No matter if I make an entirely new project, add a couple of GameObjects, make one isTrigger enabled and add an OnTriggerEnter2D to the other one, it does. not. trigger.
I took isTrigger and set it to false while the game was running, and I pass right through it, and it passes right through me. Both GameObjects have Box Collider 2D
One of the objects needs a rigidbody.
I had no idea.. All this time, and that's what it was. Thank you.
Trying to make stat files in CSV (unless you guys recommend another file format). Wondering how to grab the gameobject's name the script is applied to. Am I on the right track at least?
Also, I'm aware I don't need to make it a public void, I no longer intend to call it via other scripts.
If I'm spawning in waves, should I temporarily store the attributes? And how would I do so?
Hello people i need a help. I have edited a vs console code to display the output in Unity console. But it is not working as i expected. Can anybody help me with this. I am a beginner to these field. Someone suggested me to add void start update functions. But i have no idea what to implement inside those functions Here is my pastebin code
https://pastebin.com/Qw2x59AA
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.
yes
Pls learn to never use Regions
I don't see any code that uses these methods so I have no idea what is supposed to happen
Can someone help me out. Im tryna make a 2D platformer and everything in my code works fine except for when i press space my character wont jump, I even added a Debug.log and it works. But i cant figure out why the rb.addforce wont work
Here's my code
use continuous collision
you don't need Time.deltaTime of addForce, i think
@rotund burrow remove Time.deltaTIme
@rotund burrow is ur ground set to isTrigger?
i have 2 colliders on my player and 1 of them is set to isTrigger
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public Rigidbody2D rb;
public float moveSpeed;
public float jumpForce;
private float horizontal;
private float vertical;
public bool grounded;
public bool activateJump;
public bool jumped;
private void Update()
{
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
if (Input.GetKey(KeyCode.Space))
{
if (grounded)
{
if (jumped == false)
{
activateJump = true;
}
}
}
}
private void FixedUpdate()
{
rb.velocity = new Vector2(moveSpeed * horizontal * Time.deltaTime, rb.velocity.y);
if (activateJump)
{
Debug.Log("code works");
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
activateJump = false;
jumped = true;
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Ground")
{
grounded = true;
jumped = false;
Debug.Log("You are grounded");
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.tag == "Ground")
{
grounded = false;
jumped = false;
Debug.Log("You are no longer grounded");
}
}
}```
updated code
Does it print code works?
my character keep falling trought the platform, why?
@still tendon check if your player and platform are having colliders
i have rigidbody and box collider
If it's a 2d game use box collider 2d and rigid body 2d and make sure u don't have is trigger check for colliders
ok
still falling
Send a picture of scene window.
lol i cant screenshot wth?
i just cant screenshot it
i get this error message : this collider will not function with an effector until there is oce enabled 2D effector on this gameObject
That means you need to put a 2D effector on there
I have a question: I'm new to using instantiate, and I need to know how to Destroy(gameObject) and make a clone of it. I managed to make a clone with the instantiate how I want, but after the original is destroyed, and the clone spawns, not only does the clone have its box collider 2D off, when you turn it on and trigger it, no more spawn
Hi guys, this should only become true when it's in contact with an object within the "walkable" layer. right?
Never mind, I got it figured out. I just needed to use a prefab of the GameObject insead of using the existing one in the hierarchy
but what is that and how to add it?
On your GameObject that needs the effector, click "Add Component", and search for "2d effector" and click the one you need
oh ok
area effector surcice effector etc there soo many which one?
Well, which one do you need?
I have to go, but best of luck to you figuring it out. You got it!
have you solved? Or you need help?
help
ok send me (in DM) a screenshot of your platform and you character
yeah about that its not working i cant screenshot but i can screenshare
In Dm you can
can someone help me understand why it is only letting my character jump once
it is supposed to be a double jump
i mean i cant screenshot
but somewhy i can jump once, and then never again
i can only jump once per "starting the game"
Are you resetting isGround every time the player is grounded?
some NDA?
im pressing the windows alt prt but its not working i just cant screenshot idk why
you can easly download a software for screenshot
1 min
i sent you in dm
i still cant fix it...
thats really strange its all correct setted up
rly?
yep for what I saw. Try to put the screenshot here. Maby someone can help you
im keep falling trought the plat
Your rigidbody screenshot is missing a collider as well, it looks like.
whats that?
You need a collider on both objects for physics to work. One on your object that has the rigidbody and one on the environment, like your platform.
Hey ! I'm working on a dash system,
I want that the player can dash on the actual orientation and that the dash have a flat distance. My actual problem is that my horizontal power of dash is not the same as my vertical power (when I press the dash key, if I dash in Y axis, my character will dash a lot far than if he just dash on the X axis), I probably miss something ^^
someone have an idea why ?
There's also the dash effect instantiate on this code, this one works
ohh yeah its working now i can have a character on a platform now finally onjly took 2 days to do it
soo can i get some movement script pls
I know I posted this before but I'm still having trouble with.
it works fine in some scenarios such as in this image. represented with a yellow Gizmo
but if I add a object close by, it doesn't seem to work properly
The Gizmo
I have no clue why it does this.
The vector2 parameters for Physics2D.OverlapArea are supposed to be the Top-Left corner and Bottom-Right corner of a rectangle to check
DrawWireCube parameters are a center and size. Not a TopLeft/BottomRight pair of points
I see, is there a Gizmo that uses a Topleft and bottom right?
I don't believe so https://docs.unity3d.com/ScriptReference/Gizmos.html
2d movement script pls
No one is going to write your code for you, if you have specific questions we can help
noone have a 2d movement script?
I suppose it would be easier if I used a sphere since it will use a radius
Well, thanks Squeaky clean for pointing that out for me.
No problem. Yeah a bit inconsistent in their parameters. It's not too difficult for a square to convert back and forth between center/size and two points. You could make a pair of functions to swap back and forth as you need
The position of the two points is basically center +/- (size / 2)
Just wondering, if using a tileset for the grid should I change the scale of the grid or the cell size if I want to make it bigger or smaller?
they seem to do the same on the surface just wondering if there is something im missing
If I'm understanding right, I don't believe you can set the scale of the Grid component. But you can set the scale of the Tilemap component. But scaling the Tilemap only works when Orientation="Custom"
Uh guys
Is there a special function for manipulating some value of all gameobjects in camera's view?
Like inbuilt?(something like OnCollisionEnter2d())
Even getting a reference of all those objects would be nice
@left lotus I'm not sure if I completely understand but it seems to be working fine changing the cell size, thanks anyway
hey, so im trying to make the player flip (gravity) when it touches a square
here's my code btw
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FlipPlayer : MonoBehaviour {
void OnTriggerEnter2D(Collider2D other)
{
if(other.CompareTag("Player"))
{
//what do i do
}
}
}
If you want gravity to only change for the player, you can set the gravityScale on the RigidBody2D Component to negative https://docs.unity3d.com/ScriptReference/Rigidbody2D-gravityScale.html
If you want to change gravity globally, you want to change Physics2d.gravity
https://docs.unity3d.com/ScriptReference/Physics2D-gravity.html
This is assuming you're using the Unity physics and gravity. And that you haven't written your own code to handle gravity instead
oh cool thanks
im watching this tutorial https://www.youtube.com/watch?v=QGDeafTx5ug and how would i change the jump script so i only jump once
or should i just reset the code and find a better tutorial
or do you only want the jump script
i only want to use a new jump script
because wolfs script is movement + jumping
so, could i add in the jump script to my current movement script?
idk
how can i make clouds go slowly without script?
public variable that you can manually increase?
Use the animation system?
how can i make that in animation?
rb.constraints = RigidbodyConstraints2D.FreezePositionX; is it even possible to unfreeze it and how?
like i want only x position to be unfrozen
Seems like the the answer in the link explains how to do exactly that.
Hey everyone! Newbie developer very much enjoying his first few weeks in Unity, was hoping someone could send me to a tutorial regarding using 3d shapes in a 2d world. Video tuts are best but any reference would be appreciated ๐
I don't have specific videos to recommend, but searching with the term "2.5D" will help you find what you want
haha thanks squeaky, yes lots out on that subject
@left lotus is it alright to post a picture here?
Why is this hapenning?
Seems to be, I'm not a mod or anything
this is along the lines of what I am aiming to build
just don't know enough to call it 2d, 3d or between haha. Would you say this is 2.5?
that's a wonky error @heavy gale
That particular image looks like it's using sprites, so it would be 2D isometric.
Thank you Osteel, the terminology will help alot I'm sure
I'm doing a top down 2d game and I want the camera (which follows the player centered on it) to be able to move forward (not infinitely) with the mouse pointer when the player aims down
I'm kinda lost... Any suggestions on how to do this?
I'm thinking of something like getting the vector between the player's position and the mouse's to get a sort of halfway point
That sounds like a good idea to start with yeah, and maybe a maximum distance, at which the camera stops following your formula
I tried this but no luck
So Vector2.Lerp doesn't take a speed, it takes a value between 0 and 1 that represents how much it should interpolate between the first Vector2 and the second Vector2
e.g. with the third parameter equal to 0.0, it's the same as the first Vector2. If it's equal to 1.0 it's the second Vector2. If it's 0.5. it's halfway between both
what does this mean NullReferenceException: Object reference not set to an instance of an object
Post your code friend
it means you're calling an object that's not properly assigned to
can you click on the error
and send a screenshot/copypaste the line that's giving you trouble?
okay... can you show me where you assign playerActionControls, Land, and Move?
The problem is probably there
Sorry bro my WiFi went out
ok, so i have my gravity switch
and i can't jump while upside down
Your jump is probably applying a globally upwards force
when i multiply the jump force by -1 on the key press and flip back regular, the jump kinda breaks
How does the jump happen. Does a jump force of -1 work with however you're doing the jump force?
huh??
hey im having in issue with unity2d where if I view my panel its not there in the game view. any ideas?
the top photo is what i want it to show but the bottom photo is what it is showing
hang on i think i know
nvm it didnt work
i was thinking it was showing the main camera but when i move it to show it it still doesnt show it
yea wherever the main camera is it shows the bottom photo
private void Update() {
mx = Input.GetAxisRaw("Horizontal");
if (Input.GetButtonDown("Jump") && IsGrounded()) {
Jump();
}
heres my jump script
theres also a float of jump force = 20f
That's not the jump script, Jump() is your jump script
Though actually, could it be related to IsGrounded ?
it is, i just realised
because the groundCheck is on the bottom of the cube
thanks
wait but how do i move the groundCheck up on the keypress?
i think there's not enough info...
do you have any code in that object's start() or update() that might be hiding it?
or a sorting layer issue?
Well it works when I attach the UICamera to its Canvas but I wish for it to be shown on the maincamera
Whenever I use the UiCamera it only shows that panel
But with the maincamera I see all three panels but the middle one isnt there for some reason
are all three panels on the same layer?
sounds like possibly some of them are on UI and not others
I agree with you @dreamy egret
@gleaming nebula Can u share scene view during game play?
Which using canvas type? Screen-space or overlay?
It says screen space - overlay
use the world space render
?
@gleaming nebula Can you try put camera to scene and select render screen space - camera from canvas
Ok
and select render mode of canvas to screen space camera
Ok it shows now but here is what is wrong now
So i drag to go to the next page
And when i drag it goes through all the pages then out of the panels
Also why is the checklist now in the same page as page 1?
Should I move it till its right?
Do u have a any remote controller app? like team viewer
Can u share your id & password privately
quick question, how come this isnt working? it doesnt seem to change the boolean (sorry im new, and I'm still learning)
Yea, I know there is Input.GetAxis but I kinda wanna use GetKeyDown at the moment
you've declared it locally as true, so it'd always only enter the first if statement and only on the single frame where you press space
private bool goingDown;
void Update () {
if(Input.GetKeyDown("space"))
goingDown = !goingDown;
if(goingDown)
transform.Translate(down-etc);
else
transform.Translate(up-etc);
}```
Unsure whether this is what you were going for, but that's how I would write it simply
@still tendon sorry for the slow response!
No need to be sorry!!
Thanks so much for the help!
I forgot that I added it into the update instead of start lol
and good tutorials for a 2d platformer aim and shoot?
This is a run of the mill fade coroutine
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.
Makes the gameObject flicker tho
any ideas?
if anyone knows any... dm me.
anything with decimal points has to have an f after it right??
i.e ```cs
yield return new WaitForSeconds(0.3f);
Anything that is of type float, does yes.
If you want to use it someplace that expects a float instead of a double, yes
typically there's little in Unity that uses doubles (ie. decimals that don't have an f)
oh wait f stands for float?
yes
neat
soo how can i make an invisible wall like at the beggining of the level but i cant see trought you know what i mean?
Make an empty gameobject and add a collider?
but the camera can see trought
I'm confused, dont you want it to be invisible?
oh sorry cant*
you know like in mario at the beggining of the level there is an invisble wall you cant go trought and the camera is not moving
You mean like on the left side of the screen?
yes
Oh, okay. Thats a but tricky, you'll have to define a region on the screen where the player is "progressing" and while thats true move the camera with the player. Are you using physics to move your character?
what?
Is there a rigidbody on your player?
yes
Okay then you can just attach a child to the camera that is just a big collider, and use layermasks to make sure it can only hit the player
just add another one from the menu or ctrl z
the cinemachine is not working now
Can somebody give me an idea here
I want all my enemies visible on screen to get alerted if one of them gets alerted
how do I do that?
basically using a raycast hit 2d to turn isAlerted to true, how to set isAlerted =true to all enemy entities present in screen?
Easiest way is find all by tag and then check if they're on screen
through Renderer.isVisible right?
There are probably like a dozen ways to do that, so which ever way you like/works for you/performs well is good
I tried with Renderer.isVisible but apparently the gameObject is visible at all times
any recommendations?
google hits only gave me renderer.isvisble
renderer.isvisble is totally fine and probably the best performance wise. If you need to have more control you can do worldtoscreenpoint and manually check it
huh, thanks
you can make a static bool call alerted then if one od them sees the dude flick the switch
He just wants the ones on screen though, you'll still have to check
ah ok
But yeah otherwise thats the best way
Guys, I want to make DASH like Maplestory, can someone tell how to make it? I have tries many ways, but the result isn't the thing i want.
I dont want to make a dash by setting rb.velocity = new Vector(dashSpeed * direction)
I had tried to make a timer to let it run ใrb.AddForceใseveral times
I had tried both Impulse and Force , but ...
I Want to make a effect looks like the player is pushed by a Force.
My english is a little bit bad, so if there is something can't be understood, i will try my best to explain...
no, I tried...
it just...looks like dash in a straight line in the air
that is not the thing i want
If (GetButtonDown) rb.AddForce(new Vector3(dashSpeed*faceDirection,0),ForceMode2D.Impluse);
It will be so weird
I saw an article said it will be better if you use GetButton, but it will be better if we can use GetButtonDown to DASH
GetButtonDown fires once when you press a button
GetButton fires every frame the button is pressed
I know, I know
I still don't understand what you mean
well... wait me about five minute
I want to record dash in maplestory
and the dash in my game
okay
There is a weird move in the second video, it is my dash
not the double jump
if we use getButtonDown to Dash, it will suddenly teleport to right/left, or just do nothing
by the way , i use impulse
...WELL, SORRY About wasting your time, BUT I KNOW HOW TO deal with it...now...
uh, could have pinged me but okay
wait me a second, i will post my video how did i deal with it
THE Reason is the dashtime is not longer...enough
Hi, a quick question, is there a way to zoom in and out while being "pixel perfect" ? I guess it is not as it involve using float number zoom level to smoothly go from one zoom level to another
My goal would be to achieve a smash bros like camera, with pixel art assets
Hi, I am trying to make my first 2D game. For some reason, this doesn't work. Any idea why? (I will include the errors below)
Instantiate will return the same type of object that you pass in as the first parameter. Since you're passing in a Transform, it will return a Transform, which cannot be assigned to a GameObject variable
I want my enemy to shoot repeatedly with certain intervals between each shot
How do I instantiate multiple bullets with some delay ?
very dumb doubt but I'm very stuck
thanks!
@heavy gale I haven't tried the code, but I can give you some idea?
sure
assume a value which is called delayTime, put it into update and: delayTime = delayTime - Time.deltaTime
it's a concept, like timer
if delayTime < 0, shoot one ammo and reset it
then repeat, until something disable(shoot == false)
Yeah that's a way
Thanks @boreal knoll
How about using InvokeRepeating(function, timeToStart, repeatRate)
I don't know much about this code
And using gateway boolean to execute actual code
I 'm sorry ๐ฆ
Hey no problem thanks for an idea
I just saw this program today, so I haven't studied it yet.
how to change mouse cursor position
does anyone know how to combine two different objects into one object (spawn an object and delete the two objects) properly? i tried a tutorial but it didn't work for different objects
There's multiple questions in here, could you break down what/why you're trying to accomplish so we can have some more context?
Ok
So basically I want to do a combine game where you take two objects and merge them together into a single, new object such as combining an acorn and a mana crystal into a tree
i use the mouse to drag and drop them together
this is what i tried for the combine method, it works for duplicate objects that are the same (mana and mana) but not different objects (acorn and mana)
Could you just place both of them inside an empty gameobject, so that gameobject is now the parent of both? (and you can have any components related to combined objects on that parent gameobject)
ohh i see
How many of these recipes do you plan on having?
You may want to look into learning how ScriptableObjects work, then.
If you find yourself having to manually type "Mana" and "Acron", it's already too hardcoded.
๐
I wanna toggle my button, what do I need to put after the . ?
buymobButton.GetComponent<Button>().
I need a method that can toggle the button completely
Do I need to make my button static?
Toggle, how? Make it invisible?
Hey Im trying to make a 3D game, but using sprites in a 3D space. An issue im coming up against immediately is how the sprites look when i run the game. As you see in this image they are a little distorted? Any thoughts what would cause this?
probably perspective of the camera
you can probably model a 3d shape of the 2d sprite and put it into the game
easier to control that way i think
not sure what you're expecting to look like but yes, the distortion you're seeing is called perspective.
You could experiment with different camera settings such as an orthographic camera or different field of view or camera angle.
I guess im wondering why, when my sprite is 16x16, why its cant keep its quality, and just get bigger/smaller? why does the perspective make my edges wobbly
try point filtering
in the import settings
but if that's what you were concerned with your image didn't illustrate it
yeah I have set that
so wdym by wobbly
doesn't really mean anything unless you show what it's supposed to look like?
Hio guys. who can explain me how to create maps? But not simple tile map or such
Korean-Chinese like tile maps.
For example, we have a bunch of images 300x300 from pre-drawed map
Like that
Umm, and any example how to create such background + probably they have a +1 layer above for virtual "tiles" where is defined where you can walk and where nope. And such grid also used for character walking..
But i did not find any tutorial for such type of maps... Mostly of them - simple tile map and not like this. Hmmm
TryGetComponent is returning false even if gameObject has target component?
share code and screenshots?
Is HealthManagement also attached to the same object?
just to make sure - i notice this screenshot is from using the debugger - did you check the gotAnimator bool during this screenshot?
Becaus ethat line of code has not run yet in this screenshot
nah
if (!gotAnimator) Debug.Log("This object does NOT have an animator", this.gameObject);
then when you see that log in the console
click on it
one time
it should take you to the object in the hierarchy
just to make sure you're not getting a false negative from another random object you accidentally left this script on or something
Turns out after logging the bool, I do get gotAnimator as true
But then why in my script is it skipping that check completely
where
wait let me paste my code
public int health = 10;
public GameObject deathEffect;
public Animator anim;
private bool gotAnimator;
private void Start()
{
gotAnimator = TryGetComponent<Animator>(out anim);
Debug.Log(gotAnimator + "yes");
}
public void TakeDamage(int damage)
{
health -= damage;
Debug.Log(health);
if(health<=0)
{
Die();
}
}
void Die()
{
if (gotAnimator)
{
anim.SetBool("isDead", true);
}
else
{
GameObject newExplosion=Instantiate(deathEffect, transform.position, Quaternion.identity);
Destroy(gameObject);
Destroy(newExplosion, 0.725f);
}
}```
if condition doesn't get passed, all objects having
isDead and an animator
execute the else function
Which is just an anim of a pixel art explosion
debug that part of the code?
Wait I'm just really dumb
Sorry mate this was so bad
It works all right
the animator controller state had no motion
no worries
anyone know a decent free laboratory/factory bg for a placeholder bg?
umm hello i would like to ask some help with my project
I'm new to unity and with help from tutorials I manage to make this
its a tower defense game. I'm working on placing towers for now and i manage to make so that whenever I click on the green circles it will spawn a tower but I can't choose which towers i want to place on that spot, i was thinking of making it like Plants vs Zombies where you can drag the tower you like on the spot but i don't know where to start
Hey
How would make top down movement where my character faces the direction it is moving in
But smoothly
So, I am very much not a great programmer but I am working on a project in Unity. I am making a minimalist 2D city builder with Tetris mechanics. In terms of establishing a baseline bit of coding, I have some idea of what to do, but it will be tricky. Essentially I want the player to be able to drag and drop their given piece and then once it's placed I want it to snap into place, sort of like placing a tile in a tile placement game. Are there any tutorials that would be helpful for making this sort of thing?
Hi guys, i'm trying to move a ball on my screen. The thing is the ball is moving only in -Y. Any suggestion is appreciate, ty
transform.Translate(ballDirection * Time.deltaTime * ballSpeed);
Vector3 ballDirection;
I'm trying to get a top down movement script to work but i'm extremely new to coding so i dont wanna f anything up. can someone help me?
and these are the errors that show up
got this ^^ from a youtube video.
you're mixing up positions and direction vectors.
Missing a semicolon on line 8
thank you
Assuming this is using the new input system, that name is going to depend on how you named your Action Map in the Input Actions Asset
Make sure the capitalization is correct
Is it Movement maybe?
ah yeah I can see in your screenshot in the bottom right
it should be Movement capital M<
I see that your Visual Studio is not set up properly
otherwise it would be giving you auto suggestions etc
IT WORKED
Try following this page to set it up: https://docs.microsoft.com/en-us/visualstudio/gamedev/unity/get-started/getting-started-with-visual-studio-tools-for-unity#configure-unity-to-use-visual-studio
@snow willow can i get some help too?
I am a bit confuse. May you explain it to me with some exemple if you have time please?
transform.position gives the current absolute position of the object in the world. But you are taking that value (scaling it somewhat by deltaTime) and passing it into transform.Translate. So now suddenly the distance away from the world origin (0, 0, 0) is going to become your speed!
Ty both of you. I will work on that. At least I understand a bit more about Vector.
Hello guys, i'd like to do a delay before an animation, do i have to put the delay on script (before i trigger smthg) or i can do it directly on animator of unity
PS: I'm very new to coding With that said. I need help connecting animations to movement
I've already set up the animations, i just dont know how to link so that when i press w (move upwards) it plays walk animation up
You can start by not capitalizing the start of each word.
But it means that you haven't told your game what winText is. You probably need to drag it into the inpsector.
so im looking at menu tutorials, but whenever i create a new scene, i always see the other scene, instead of nothing there
and then all the tutorials the other scene disappears
how the frick do i add A FRICKING IMAGE ASSET!?!?
To import an asset to your project, you just add it to the Assets folder.
Now, what? What are you trying to do?
does anyone know why this isnt being triggered
when i put a image why does it count the transparent part?
hello?
check your import settings
where is that? ._.
CLick the image in your project folder
there are import settings for it. And every asset
huh
its is on serialfield but even if i gonna do it on public still not working
can you screen shot it sorry if im being to frustrating
ys
you can't reference objects from your scene from a prefab
Not permitted by Unity
It wouldn't make sense.
What would happen if you instantiated your prefab in a different scene?
Singleton pattern or FindWithTag
those are the most straightforward ways to find your canvas
or when you instantiate this thing you can run GetComponentInParent<Canvas>()
any of those three are quite straightforward
but it will have to be done in code no matter what
oke how do i need to do it in this code
I just told you three ways
with tag
tag your canvas
but how to find it
but its not and gameobject
this?
if i gonna call the canvas a gameobject the canvas.scalefactor is not working
You have to get the Canvas component with GetComponent after finding the object
i clicked this
all it shows me is the image tho
why did you click that
all we wanted was the import settings
underneath that open button
is all the import settings
that did not help me
STUPID SPELLING ERRORS
idk what to change
bruh
nvm i fixed it
https://assetstore.unity.com/packages/vfx/shaders/fullscreen-camera-effects/simple-2d-fog-storm-smoke-115617 I have tried implementing this code in my project. I can add it to the camera object and it works (it has to be on the camera object because it's using OnRenderImage(). Unfortunately my camera isn't strictly following the player but rather lerping towards the player to have a "smooth" camera and I think that's the reason the whole fog shader gets moved around as soon as the player starts walking. I don't really know how to fix this, any ideas?
why the frick is this not working?
you should remove the + beside the equal
and if you are making a 2d game use Vector2
basicallly the same as Vector3 but with the z coordinate removed
to avoid confusion
ok
variables usually don't start with a capital letter, use lower letters to differentiate them from methods
plus why did you put it the speed at 1
put it at like 10
if the thing disappears
its working
coz sometimes it would be too slow to see its movement
the player
coz its so fast it ran off the screen
I doubt you made a camera controller yet so I am certain you wouldn't be able to see it fly to where
im raging so hard rn bc its not moving
its probably the speed
try set it to 100
or even higher
so you can see its working
coz it dashed out
you're a beginner so there could be a lot of reasons... is it attached to the player object? Are you in scene view or in game view? etc.
you know what
the scene view kinda doesn't matter
ill try to make a dif game
I was stuck there once and felt like an idiot... scene view (at least for me) doesn't react to keyboard controls
awe mate, don't give up on a 2d unity game
but i did just now ._.
oh thats something new to learn
wait a minute
why is your input
input and not Input
why tho? that's part of programming. you'll have a big problem that stumps you.
im gonna work on a 2d platformer im done with the shooter idea
that's a good catch, I was confused by the highlighting too
programming is about making the code more simple and easier to read so if you found an error you wouldn't just quit coz of lack of motivation
like me
my movement logic is different but I actually tried his code and it worked