#πΌοΈβ2d-tools
1 messages Β· Page 44 of 1
nvm, I'm done, I got all of it working ima take a break from unity for today
I might have a problem tomorrow tho
we'll see
oh you know what, I will
I want a way to win
welp
bye
https://pastebin.com/YQ5u86XZ I'm trying to get my movement out of Update and into a FixedUpdate, but I'm not quite sure what I'm doing. Can I cut the else if statement with UpdateAnimationAndMove in Update and make it an If statement in FixedUpdate, or what steps do I need to take
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.
that fixed it
Ooh also if anyone can suggest a tutorial which displays how to split one tile into multiple, that would be really helpful π
Hey how to change light2d pipeline volumeopacity
you set your sprite type to mutliple in the inspector
and then go in the editor and it should be pretty intuitive
hey i was reading over the docs.unity to find a way to make a object in a 2D game only travel in 45,135,225,315 angle diagonals. The closest i got was rigidbody.constraints, if anyone has any suggestions I would greatly appreciate it. π
Can you explain what that means?
You gotta code that on your own
Probably diagonals where the numerics he's mentioned are degrees.
Oh i was reading that as 45 billion etc
Same at first
okay sorry. i'm making a object in a game that i want to restrict it to only move in these 4 directions.
Are you using a grid based system? Or free movement?
free movement
So only move it that way. You have full control over the motion of any objects as long as you don't use Rigidbodies
You could constrict the Input
how would i go about doing that? the initial input sets at those angles but as soon as it collides with anything it gets knocked off the path and travels in any direction π
i tried to play around with rigidbody restrict but I was getting no where with it
Else I'm guessing you're looking for some built-in way to simply constrain movement; which isn't available. Rotations can be constrained easily because they are states of your Transform (Object). Movement is more of an event process and would not be defined after the movement had been done (you wouldn't know where you've moved without evaluating movement).
Sounds like you are wanting to tamper with Unitys physics and likely will need to roll your own collision/deflection system.
Make the object colliders type trigger and process the collision events yourself?
agh thought as much. I just felt like i was missing a simple built in command because it seems so basic moving in the 8 directions. I will try coding my own collisions to affect the transform.
sorta if it is traveling left to right* collides with a top of a block it will transform towards (y1 , x1)
cheers for your time though lads
{
void OnTriggerEnter2D(Collider2D other){
if(other.CompareTag("Player")){
Destroy(gameObject);
}
}
}``` Is my code right? Whenever I collide with the coin, it never destroys the object. pls ping if you have an answer
Code looks ok but did you set everything else up correctly?
Do both objects have Colliders?
Is one or both of the Colliders a trigger?
Does at least one of the objects have a Rigidbody2D?
yes, wym, and yes
Is the player ragged properly?
IsTrigger checkbox on the collider
OnTriggerEnter2D is for trigger collisions which is when one of the objects is a trigger
Otherwise you use OnCollisionEnter2D
if i use oncollision do am i able to use it if 2 of the colliders have ridgid body
Yes
nice ty
But neither one can be a trigger
Im using the same code like @fast siren but with my code it wont work, i got all like in the tutorial.
what can i do now haha
show code
ehm how do i post it like yours xd
[SerializeField] p rivate string sceneName;
void onTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "player")
{
Debug.Log("Menu");
SceneManager.LoadScene("Menu");
//SceneManager.LoadScene(sceneName);//
}
}```
this is my code for quitting it would be better if this work
{
if (collision.tag == "Collectable")
{
Destroy(collision.gameObject);
gem += 1;
}
}
and this is the one for coins but yea nothing works
okay hm lets see
private can't have a space in it
OnTriggerEnter2D must be capitalized
most likely "Player" tag should be capitlized but maybe not if that's the actual tag your player has on it
if (other.CompareTag("Player")){
{do whatever}
}
}
yea it is
try that
walk through like it's nothing,I have an error but I don't think it has anything to do with it, it's about Edge.WakeUp ()
do I need a certain layer or is it simply default
Update in playmode it worked someway, it stopped and threw me out of the game and not into the scene "menu", when I tried build and run nothing happened again
if i have multiple objects with a single script attached , i have it such that when that object interacts with another object it stops movement and attacks that object. How do i differentiate between the current object that is colliding with the enemy object from other objects that are not colliding with anything?
does unity has a built in sprite deformer to bend a bow?
hey does anyone have videos on how to place assets in a grid form i'm new to unity so i'm not used to this stuff π
@ me when u have answers pls
Thank you @lament spire yes I created a new project and figured that part out last night
I would like to learn more about tiles, tilemaps, and tile related products π Does anyone know any resources that helped them with this?
private void SelectTile(Vector3Int tilemapPos)
{
print("selecting tile at " + tilemapPos);
this.tileMap.SetTile(tilemapPos, this.selectionTile);
Tile tile = tileMap.GetTile<Tile>(tilemapPos);
print("tile: " + tile);
tile.sprite = this.selectionSprite;
tileMap.RefreshTile(tilemapPos);
}
Hello again π I am trying to highlight a tile on the map, and I've googled around this seems to be a common problem, maybe someone here has insight? Neither changing the tile, the sprite, or both the tilebase and the sprite make any difference, and refreshing the tile does not show a change either.
How can I do this: ```CSharp
TileBase tile = new TileBase();
It might have to do with the tilemap.refreshTile having so many spaces infront of it but thats probably not it
I allready solved it but still thanks for trying to helpπ
No worries π
I figure it out π Thanks for letting me unload my thoughts π
Hey guys,
I want to add slope support to this code but after spending a few days I have not added it yet.
Any idea ?
https://www.roystan.net/articles/character-controller-2d.html
hey so i'm was writing a code to spawn a door in the middle of the room when the boss dies but it keeps telling me it's a null reference when i try to use the function. I have made a game object and put a prefab in the slot in the inspector. Would anyone have any idea why it's not working? π
` public void MakeDoorVisable()
{
//spawns exit door under the position of the main camera
GameObject tmpObj = Instantiate(myDoor);
tmpObj.transform.position = Camera.main.transform.position;
}`
myDoor is a public gameobject at the top of the code block btw.
which line does it say nullref?
i have a call function in another script to test it
the underlined line is where the the runtime error points to
is your "test" assigned?
it's at the top above update
assigned. not declared
you'll need to drag your nextLevel object from the scene into the "test" variable field of UtilityBehaviors's inspector
oh okay π
thank you so much i'll test it
i dragged it into the inspector and it's still saying null
i'll try moving the whole function to another script to see if that changes it
could you post your UtilityBehaviors and nextLevel scripts in a paste site here? and the error you're getting
Are you sure you have βmyDoorβ assigned? @lost temple
Actually can you show where you assigned βtestβ? If thats not it, Iβm stumped
I just moved on to disabling the rigidbody and to change the sprite on the function now. it seems to be working lol
Alright
I dont think thatβs where youβre supposed to assign it. You need to drag it into the UtilityBehaviors script that is attached to an object in your scene
Which leads me to the question of did you attach those scripts to objects in the scene?
yeh i have a object with next level in the scene just attached unitybehaviour to the player
still null refference
i'm just gonna disable the collider and change the sprite on function. idk why its not working
Ok
Can someone Help me with my problem because I cant understand anything
I can send the script if someone needs it
Use a bin site to share code. Also, specify your issue.
hy
someone now how to make a destructible block in unity 2d
with a life
i want to make destructible terrain like minecraft2d
and how to make a block hill which can get climb
by car
google marching cubes
hey, sorry but is there any chance I could get some help with some wall jumping im trying to implement?
can someone help me with animating my player? I set it all up, but it does not properly transition from one state to another even though it's all set up properly. Basically the state does not change from idle to run, run to jump, etc.
So when you move your character, the bool variables or whatever you use change state correctly?
I am not sure. I seems to be all correct, but I am not sure
I am just a beginner. haven't really done too much in unity.
and how old is the video you are following <.<;
Well, if it's brackeys tutorials, then they are pretty outdated.
yeah it is
there are several ways to make 2D character controllers.
ok
so it's a bit hard to just take one video and go with it.
ok
https://www.youtube.com/watch?v=n4N9VEA2GFo
This one is a bit more up to date and quite simple
In this video we cover 2D character movement and jumping for Unity and C#
This video is part of our "In 5 minutes" series where we show you exactly what you want to know.
Want more 2D tutorials?
Projectiles = https://dps.tips/2D_Projectiles_YTn...
i will get back to you if I fail again
Im having an issue that when my character wall jumps they move constantly along the x-axis until the hit a wall, anyone ever heard of this issue?
Hey does anyone have any insight on how to place my sprite in tiles Iβm really new to unity and I need help or a video that can help
nvm i figured it out
I really don't want to rewatch this tutorial, but I guess I have to now
wrong channel...
hey @grand cove. I looked over the video you sent and messed around with it a little, but it still does not work. Can you take a look at all my work to see if you will find any mistakes?
can someone help me in #archived-art-asset-showcase ?
Does anyone have the time to explain what am I doing wrong ?
Well, one thing you're doing wrong is expecting someone to invest time without knowing what the issue is.
Secondly, don't cross-post.
I need a bit of help. I don't know why it says this. I'm making a grappling hook, but the Console is saying, "Cannot create the 2D joint on 'Player' because it connects to itself. It shouldn't be connecting to the player, it should be connecting to the "ground" layer or "foreground" layer. Can someone please help me? If you need any more information let me know. π
I'll send my code if you need it. I'm not familiar with this error but I don't think its in the code. (Yes yes... I'm following a tutorial.)
The third parameter to Physics2D.raycast is the maximum distance for the ray
So when you pass in your LayerMask - I believe it's being interpreted as an integer and used as the maximum distance parameter instead of the layer mask parameter
If you mouse over the raycast call it should show you what each parameter is
what could be causing two boxcollider2Ds, both with rigidbodies, to not push against each other? When I run my program I'm able to make them just completely overlap, they don't seem to detect each other at all
I turned off one of my colliders and it's better but I need both of them in order for my game to work π₯Ί Also when I fire it throught my foot collider it doesn't work.
I basically want it to ignore player colliders.
I know I'm trying to help you do that
The problem I think is that you're not passing the parameters correctly to the raycast
Thanks. Sorry I was just telling Nivrap that. I'm trying to figure out what you meant. π
Thank you Nivrap though!
I think you're right. I don't know what I should do.
I'm very basic level at coding.
If you mouseover it in VS you get something like this. Make sure the parameters are what you're expecting
Ohhhh
your mask should be going into the layermask parameter and not something like max distance
DO they have Rigidbodies or Rigidbody2Ds?
rigidbody2Ds
Is either one a trigger?
no
How are you moving them
@lament elbow @crystal geode is asking a completely unrelated question lol
one of them is X and Y locked, the other is a child object of my camera, and it moves along with it
you guys have such similar names π
well - yeah - and the one as a child of the camera is kinematic?
The X/Y locked one can't move at all, and kinematic rigidbodies don't react to forces or collisions at all anyway. So naturally you cannot get any reaction out of them
ah, that might explain it then
let me try something...
hmm
so when I lock the X and Y of the one attached to the camera and make it dynamic, the camera can still move it
yes indeed
X/Y lock stuff is related to the object moving from forces
awesome
it doesn't stop scripts etc. from moving it
You still have one that's kinematic and one that's X/Y locked right?
no, both are dynamic and X/Y locked now
ok so if they're both x/y locked then they will not move from forces
that's what it does
right, I don't want them to move
I want one to basically act as a barrier
and stop the one that's moving with the camera
that means that one of them would be moving the other
ah
I see
hmm
so I need to have some way to have my camera box not X/Y locked
but still not fall due to gravity
and not be kinematic
the barrier one should be kinematic. The one that's a child of your camera, you should make not a child of your camera, You should instead use MovePosition in a script to move it to a transform position that is a child of your camera
also re: gravity just disable gravity on it
I don't know if this helps with my question.
Lemme know if I'm interrupting plz
Looked like he had the answer π¬
See how in this screenshot the third parameter is distance
and that's where your mask is going
that's not good
OH this is all making a lot more sense now.
try:
(Physics2D.Raycast(transform.position, targetPos - transform.position, float.PositiveInfinity, mask);
Can anyone please tell me what is wrong with this
Without the context as to what is wrong, it is very hard to tell
but I imagine you're running up against OnCollisionEnter2D not working
and that's because you are moving via Transform
and not by physics, like Rigidbody2D functions
If it gives you a null reference error, then try checking if hitInfo.collider != null before checking go the tag
Well if I look better you shoul check if the object that has been hit actually has an enemy component
Hi how can I get the lastMove direction of my player?
I allready tried a own method but both keys would have to go up at the same time for it to work the way i want.
Any ideas?
I have no clue as to why the animation that isnt playing is affecting the rotation
ping me if you have something to say about my situation
Is weak attack supposed to change the rotation?
yeah
could you show me the animation in the animation tab?
but it does wiggle arround
or is the wiggle not the animation?
its the animation
The problem is
The dagger is supposed to aim at the mouse
when the animation isnt playing
and that part isnt workin?
but the dagger only follows the mouse when I delete the weak animation
its somehow stopping the dagger from following the mouse
even though it isnt playing
try rotating the weaponRot with the mouse and weapon place with the animation
rotating the weapon place wouldn't rotate around the character
are animations that arent even playing supposed to affect objects
sorry im stupud
try making that animation in the script using courotines if nothing else works
@mental idol
sure, thanks
but is it supposed to do this
is transform.localRotation not a thing?
i can't get it to work (trying to flip my character)
I'm trying to change the material of an entity using the new Entity Component System
In the entity debugger it looks like it is working and changing the materials, but it does not update in the game view
They are all blue/yellow, but in the entity debugger, some of them are linked to a red/black material
Why does this happen?
How do I have a button say in one position in my 2d world instead of staying on the main camera?
Either turn the button into a world space sprite (SpriteRenderer) or use a World Space canvas and leave it as a Button
Just set the render mode of your canvas to World Space
Oh ok and that will lwt me place it anywhere in my 2d world
yes
does anybody know how to do custom physics for 2d space like for example that my player is staying on the ground or wall or cealing or is just attracted to the nearest point that belongs to an object with a specific tag.. I searched on the internet but somehow im too dumb to understand it
custom gravity? Sure that's simple enough
Just do this in FixedUpdate:
rb.AddForce(myCustomGravityVector, ForceMode.Acceleration);
is the customgravity vector really just a x and y?
it's a Vector2
so yes
obviously you'll need to calculate the direction and magnitude of gravity
if it's for a planet you can use the standard gravity formula
no no planet
you can add the gravity force if the player is inside of a trigger or a length between check
is it also possible to use raycast? as if my raycast hits the ground the gravity should be set to the ground angle?
ye raycasts work
okay thanks
raycast would be kind weird imo
to do the raycast you need to know the direction to the thing
and if you know the direction to the thing, that's already the gravity direction, no?
the direction to the planet is players position - planets position
Maybe I don't understand exactly what you're going for
right and that's also the gravity direction
well the other way around technically but still
well I already have the angle I just need to know how to set the gravity to it
you can do rigidobdy2d.addforce(planetdirection)
btw when I use custom physics isnt then my complete movement script for the bin?
you will need a custom movement script probably yes
okay
oh and btw its a 2d game so theres only impulse and force what should i use?
try out every singe one and see what u like best you can olso not use it its not not needed for the force adding to work
oh and btw whats about the Physics2D.gravity ?
isnt this something I could just use?
rigidbody2d does have build in gravity
Then you use:
rb.AddForce(myCustomGravityVector * rb.mass, ForceMode.Force);
Yes if you want to universally change gravity for all objects simultaneously
but there istn a ForceMode.Acceleration
Fixed
oh okay thanks
GL making you game
thanks ! but one quick question xD do I need now to set the scale to 0 for the gravity right?
yes or set gravity itself to 0 in general
ye
since you'll be doing your own gravity
okay
appreciate your time guys
omg something is working xd but cant tell what
nvm
I downloaded a sprite pack with multiple parts(arms, head, body) per sprite. Do i assemble all the sprites parts as a game object to make one big sprite or what do i do with the pieces?
nvm
i found you can just make a new sprite
sorry for the silly question
Does someone know the name of an algorithm that combines two polygon paths (that form something like a torus) into a single polygon?
two paths (torus)
single path (polygon)
I need this for decomposing a tilemap's composite collider into multiple polygon colliders, to then generate shadow casters from their paths
if your paths never cross, you could cheat and do this with PolygonCollider2D quite easily (set two paths, then use P2D's CreateMesh)
you might want to go a step further and use Clipper, available in Extras in the 2D SpriteShape package or you can just drop the script into your project from here: https://github.com/Unity-Technologies/2d-spriteshape-samples/blob/master/Assets/Unity Technologies/2D SpriteShape/Extras/Scripts/Clipper.cs
How do I add like a timer to my dash system?
currently this is my dash code
// Dash Function
IEnumerator Dash(float direction)
{
isDashing = true;
rb.velocity = new Vector2(rb.velocity.x, 0f);
rb.AddForce(new Vector2(dashDistance * direction, 0f), ForceMode2D.Impulse);
float gravity = rb.gravityScale;
rb.gravityScale = 0;
yield return new WaitForSeconds(0.4f);
isDashing = false;
rb.gravityScale = gravity;
}
// Code in Update(), to check inputs and some other stuff
if (Input.GetKeyDown(KeyCode.A))
{
if (doubleTapTime > Time.time && lastKeyCode == KeyCode.A)
{
StartCoroutine(Dash(-1f));
} else
{
doubleTapTime = Time.time + 0.3f;
}
lastKeyCode = KeyCode.A;
}
// Dashing Right
if (Input.GetKeyDown(KeyCode.D))
{
if (doubleTapTime > Time.time && lastKeyCode == KeyCode.D)
{
StartCoroutine(Dash(1f));
}
else
{
doubleTapTime = Time.time + 0.3f;
}
lastKeyCode = KeyCode.D;
}
You mean cooldown timer or cooldown to display on canvas?
anyone know a good way to make a welding system so you can connect 2 objects together ingame?
Physics joints
I'm trying to make my Cinemachine follow my player after it re-loads and doesn't destroy. In my script it says it's finding my player but it still won't follow it.
Lemme know if you wanna see my code that I have because maybe IT can be changed, but does anyone know what I can do just to set the "follow player" ... to player, by code. While still having my player prefab enter the scene by not getting destroyed.
Hey is there anyone online that knows much about Cinemachine code that would be willing to give me a hand???
You honestly shouldn't need much code for that at all
Just make the vCam a part of your prefab
have it preconfigured to look at and follow what you want
and set the priority high enough that it will take over as the camera when it comes into the scene
I've got something similar to that. I'mma send my code image
I don't know what's wrong with it π
Seems like it shouuulld work
You shouldn't need that script at all is what I'm trying to say
Yes put a virtual camera in your player prefab
already configured to point at the player and follow it
π€―
You mad genius
I'll try that. Thanks so much π
Nah it's not working
The follow of player doesn't exist after I enter a new scene
Because I have it set to don't destroy / destroy other object on load so that I can be in a proper place.
Yeah it says missing transform
Does anyone know if it's possible to make Cinemachine follow the player Tag or anything?
I have a wall sliding (and jumping) system but for some reason my player only slides down slowly for less than a second then just falls normally. If anyone can help me fix this it'd be awesome
a powerful website for storing and sharing text and code snippets. completely free and open source.
so hey guys! im Still working on my custom Physics2D and this is my code. but theres an issue that I dont quite get.. its working as fine with the angle and stuff but my player is falling down like 2mph how can I like do him weight more.. when I add mass to him it doesnt change anything
Hi, I'm currently working on a 2D project for school and am facing kind of a problem
I am changing the rigidbody position and transform.localscale at the same time in a Coroutine with a While(), It's working, it is, but the thing is it takes about 1 seconds for the scale to get to its desired value while it takes 3 seconds for the rigidbody to get to its desired poisition... They have the same speed * Time.deltaTime, but definitely the distance between localScale vector2s is shorter than the distance between both vector2 position (startPos and endPos)
any idea how I could get the speed in sync ?
tyvm!
I,ve solved it using Vector2.Lerp
how do i give priority to hitboxes if they overlap?
im making a chess engine, and when u click on a piece it will instantiate a bunch of tiles which show the possible moves
however, occasionally it seems to clash with the 2d collider of the pieces themselves
it looks like this
it seems to prioritise the bishop's hitbox
welp, fixed it by messing around with some z-values
Seems strange to me to be using colliders for a Chess engine at all
hi guys is there any way to implement depth perseption in top down 2d games in unity??
all the tutorials i found are for platforms games
Use a perspective camera and 3D objects I suppose?
or just use other visual cues like... darkness/brightness
shadows
my project is a 2d pixel art top down game
i start thinking maybe i could use layers
i tryed to make 2 platforms with 2 layers (1: death layer/2: platform layer) and and i made them one over the other but it didnt work
Look at how other games go about it. The top down Zelda games would probably be a good study
yeah zelda is a good example! well i can make it like falling holes and and when player collide he dies but the problem here what if there is a big hole or empty area between the player and his goal and he need to pull a lever or push a switch so he can activate a bridge to cross(instantiate the plaform game object) here where the problem cause the deadly area that the player cant cross without dying and now a platform has been added on top of the deadly area how to tell the game that the player need to cross the bridge without colliding with the deadly area
Some ideas for how to make a chunk for a 2d survival game ? With what should i start?
Hey 2d devs π
Was hoping for a bit of help here, I am trying to move my camera only something seems to be blocking it. Now I think, it's probably not being blocked, the update function must only run once when I use a condition, because my camera will only move if I stick it outside of any conditions even newly created ones
I am using this bit of code to move my camera to a desired target,
cam.transform.position = Vector3.SmoothDamp(
cam.transform.position, camTarget, ref camSmoothDampV, 0.5f);
The only way it moves the camera is if it is open in the update section, not under any ifs or other conditions. I am assuming it is because this only runs once, is there an alternative function I could use like perhaps, MoveTo?
the reson its not moving is cuz every frame it moves it closer but if it doesnt get used again itll not move it it must be run every frame
moveto olso does the same
i dont think there is a way to move it slowly if only run in 1 frame
if u dont want to move it with scripts try using cinemachine its a unity add on that has alot of options to make camera movement
i found a way you could do it in 1 frame
you can use DOTween
its an animation creating with only moving parts
its animating without animation
hmm tweening yeah that's kind of what I was looking for
thank you @queen coral
I'm used to unreal alot of this is native there, still crappier though π
what about a while loop perhaps, while camera position != to target position then lerp?
π that stuck me an an infinite loop...
do I really have to use external software for this? Just want to move a camera lol
Look into Cinemachine maybe
gotta animate or something huh, okay i will check that out at least. DOTween really looked decent too just seems alot
Cinemachine is pretty awesome, I trashed all my code driven cameras once I got the hang of it
One of the best things they've added to Unity over time
Alright that sounds promising. Thanks, both of you π
Check this out for a decent conceptual overview applied to 2D: https://www.youtube.com/watch?v=mWqX8GxeCBk
Watch this video in context on the Unity Learn pages - http://unity3d.com/learn/tutorials/topics/2d-game-creation/cinemachine-2d
Learn how to harness the power of Cinemachine's powerful composition tools with an orthographic virtual camera in your 2D Project.
can someone explain me how random movement is done with a sprite? like walking around in random directions
step 1: use a function to pick a random number
step 2: depending on that number choose a direction in which u wanna send the sprite
step 3: if u want it to change direction after a certain time delay u can use a random number range function and use invoke()
wdym
like
lol
that always and when it turns (which it does) it goes forward still
its an ant it it now turns every x seconds in a random way
u mean u wanna make it continue in that direction?
but it doesnt move
no i want it always to go forward in his perspective
so when it turns it goes to another way
depending on the direction u got from the random number u add a force to that direction
wait
alright
create some if statements where depending on the rotation of the sprite it will add a force in a certain direction
i dont know why that took me that long to come up with
i think u gotta do something like
if (transform.rotation.z = 90)
{
rb.velocity.y = moveSpeed;
}
im not too sure myself
but ill put it in update tho
hello guys
hello
hi
can u send it
the script?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ChangeScene : MonoBehaviour
{
public void MovetoScene(int 1)
{
SceneManager.Loadscene(1);
}
}
this
what
thats just unnecessary
yep
u can just use scenemanager.loadscene directly
yea and then like ("Nameofscene")
yep i think its that aswell
i dosent undersatnd this
can you send me the correct code pllls ._.
well what d you want to happen
and also
the scene name cannot be an int
it should be
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ChangeScene : MonoBehaviour
{
public void MovetoScene(string nameOfScene)
{
SceneManager.Loadscene(nameOfScene);
}
}
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ChangeScene : MonoBehaviour
{
public void MovetoScene() //call this if you want to chnage the scene (call it with MovetoScene())
{
SceneManager.Loadscene("**nameofscene**");
}
}```
u kinda messed up
if u use that code
i think i did in my prjects
it works but it could be done better
but im not sure
ok
yea well
in the moveToScene function
thats all my code
u wanna add a parameter
"it works so it works"
true
i have a queastion
idk how tho
what r u trynna do
move the and the way its facing to
i dont think that has anything to do with its position
where 1 is written do I have to add the name of my scene?
yes
yah
ok nice
for example if the name of ur scene is Scene1
yes
it would be MoveToScene("Scene1");
does i have to ride it in "" these
yes
oh ok
you mean like this?
ok
over there u can just name it 1
u do that when u call the function
for example
if (somethingHappened = true)
{
MovetoScene("Free Coins")
}
but as i said earlier u should just erase that whole function u wrote and just do
if (somethingHappened = true)
{
SceneManager.Loadscene("Free Coins")
}
ok
shouldnt it be RigidBody2d.velocity = tramsform.forward * moveSpeed * Time.deltaTime
are u talking about the position or rotation
position
can u show me what happens by screensharing it
in call?
alright
ill mute myself
same
ill call u ok?
i dont have a mic anyways lol
lol
ok
transform.forward are equal to vector3(0, 0, 1) and that why its on Z, so if you need on Y you do transform.up i believe....and that equal to vector3(0, 1, 0)
how do i make it so that if it collides with "ant" it overlaps and not actually collides?
You have to use a trigger collider instead
oh how
it's a checkbox on the collider
this
you just asked me how to make it able to overlap
yes
trigger colliders don't physically collide
cuz now they hit eachother
so it will overlap
omg bruh
thanks so much lol
and no i need the collider for walls etc
thanks!!
wait
no
wait lemme test
now the walls dont work
lol
If you're trying to make it so certain objects collide with certain other objects and ignore others you should use layer based collisions
hmm
by the time you get OnCollisionEnter, it is too late, the collision already happened
yea i found out
uhm
now i find it confusing
what do i check if i want the ants to not collied but them with wall i do
collide
You need 3 layers right?
- Ant
- Wall
- Player
or youi can use Default for the player, or whatever
well i dont have a player
ok so what needs to collide with what
its just AI
and what needs to not collide with what?
the ants collide with everything execpt eachoter
ok so just uncheck the Ant/Ant box
And make sure your ants are on the Ant layer
make thier boxes is trigger?
no
unchecked right
leave the colliders as not triggers
np
now my ants walk
and dont escape through walls
yaayy lmao
time to program the brain
Hello! For some reason my button doesn't work. It doesn't highlight or click to a darker colour but i put interactable on and OnClick set? Please help
Do you have an EventSystem in your scene?
no i dont think
ok tahnk you
i added it but it still doesnt work π¦ is it because it is in a prefab? do i need event system outside prefab?
don't put the event system in the prefab
put it in the scene
what about the button does that have to be in scene or prefab?
Hey guys, how would you put in a code, if the player is touching a specific layer or tag then .......
I have a public static Player instance; in the player.
Like how would I make something like this work
if(Player.IstouchingLayer(Layermask.GetMask("Blank"))
{ Then do this.....}
Use OnTriggerEnter to detect when they start touching
OnTriggerExit to detect them stopping touching.
Hello guys, I have a question. So basically I am trying to create a game like Bubble Witch saga,where you have the tower and then you use the already instantiated object
I have Blocks instead of bubbles, and my blocks cannot go outside of the grid I have set. The thing is, I do not know how to first instantiate the object, and then shoot it accordingly. I have the Blocks be able to rotate as the user pleases
I have already made a working cursor and tower but My problem is shooting those Objects after, the game is in 2D. I tried with a way I found on youtube but it gets the RigidBody, whereas i do not have one on my objects
GameObject.Instantiate() from a bullet prefab that has a forward velocity script on it?
What's the problem with using a rigidbody
If that really doesn't work, you could adapt the same script, except in your FixedUpdate you will have to move the object manually in code
You can have a script, such as, ShootsForward, which makes the object travel forward in FixedUpdate
Have it on your bullet prefab by default
Everything kinda breaks when i use the rigidbody because I guess I always check when the objects go out of grid and relocate them, like in tetris, but when i applied the rigidbody it just fell down to the void
Ah, I think I see. Yeah RigidBody links an object to Unity's physics simulation. So if you begin messing with the position yourself, the physics simulation gets a bit out of sync
But you don't necessarily need your blocks up top to be rigidbody's with gravity and such. Only your bullet
If you set the "isKinematic" checkbox on a rigidbody, it won't move because of physics/gravity/etc. Only when you do it thru c#
But it will still be a RigidBody for the use of collision triggers and such
Yeah i get what you mean but my blocks are actually the "bullets" in that case like the bubble witch saga game which has bubbles.
Ohh okay i see
Your bullet then could either be a regular rigidbody (probably with gravity turned off), or also an isKinematic rigidyBody where you are manually controlling the bullet movement
Ah interesting, can you elaborate on the blocks are bullets things
Sorry haven't played bubble witch saga, but from the look I believe I've played similar ones
The bullets I have already have collision on them between the blocks, its like a tetris game the blocks are the actual bullets, and i want to shoot the blocks. Also i truly appreciate your help lol I am probably making fully beginner questions but ive been searching for some time to find an answer and i didnt manage to
{
foreach (Transform children in transform)
{
int roundedX = Mathf.RoundToInt(children.transform.position.x);
int roundedY = Mathf.RoundToInt(children.transform.position.y);
grid[roundedX, roundedY] = children;
}
}``` this is how i Add a block to the grid i have
and this is how i check if the blocks are outside the grid, ```bool ValidMove()
{
foreach (Transform children in transform)
{
int roundedX = Mathf.RoundToInt(children.transform.position.x);
int roundedY = Mathf.RoundToInt(children.transform.position.y);
if (roundedX < 0 || roundedX >= width || roundedY < 0 || roundedY >= height)
{
return false;
}
if (grid[roundedX, roundedY] != null)
{
return false;
}
}
return true;
}
}```
if they are not, I just use this transform.position -= new Vector3(0, -1, 0);
And the cannon and crosshair + bullet shooting is a shameless copy paste from here https://pressstart.vip/tutorials/2019/04/1/91/unity-point-and-shoot.html , which uses rigidbody that i do not have. and also this creates a new element but i want it to be instantiated first before firing
Sorry gotta be offline for 20-30, will probably be in the channel later. But just to give you something to work with,
yeah bro i totally get it You helped me enough i will try the rigidbody + isKinematic and will go from there
You probably want to stay with what you've done but also use RigidBody's with isKinematic checked so it's true, and then you can use OnCollisionEnter, and compare against a tag, or name, or similar, to see what you're colliding against
There are of course many other ways to do it, but this way uses what Unity has built in
I see, Yeah probably some already defined things will be easier for me cause i dont know a lot of stuff on this topic haha, thank you so much for your help bro I will try those
hi! im trying to resize a ui slider at runtime but i get that the recttransform whit is not varible
how can i doit?
nvm
if anybosy wonder
Is anyone online able to give me a quick hand?
Just ask your question
I'm not sure why this is looping.
I'll explain
Basically this code is used on multiple objects. Doors have an object on on them that has the tag Door and the player has the tag player. Other objects in the scene have no tag. The ones with no tag transfer you just by touching. Which works. But the doors I want the player to have to press either the uparrow or w in order to change scenes.
But the doors right now for..... some reason... when you just touch them are transfering you and are looping between scenes over and over.
I might change it so that the door object itself has the tag door and change it to gameObject.tag in the script. Just to make things easier.
If more information is needed I can send it.
it's only going to change to the Next Scene you have declared in the inspector
Yeah like this
I really like this code because I can keep reusing it for each scene I want to transfer to.
But it broke somehow and won't allow me to make it so if I stand on a door tag I have to press the up arrow.
I had it working at one point but then I wasn't able to make it so if it's not a door tag I don't have to.
So at the moment. When I climb my ladder to "go upstairs" for example, I don't have to press the up arrow. Which is good. But my door I want to have to press the up arrow. But right now it's just warping me when I touch it.
currently you would have to hold up while you enter the trigger
That's what I'd expect but it's not for some reason.
you would need to use TriggerStay to make it work when you are inside the trigger
π² What's that?
Cuz I wanna use this script for multiple things. Both for needing to press uparrow and not needing to.
Also, unsure whether you could use OnKeyDown, and might have to switch it to OnKey, as this is a physics event and is probably not called in Update specifically
That makes it work but then I cant do the "else ... (if the tag doesnt have door) then you can just walk through it and change the scene."
you would probably need to have both OnTriggerEnter and OnTriggerStay and handle each of those cases in them separately
OwO
I'll try that thanks
This also doesn't work. Might not have been what you were talking about too.
That's back to front, and you will also have to handle the "not door" part of the automatic transition
Does anyone know how to set raycast to where you touched on screen(IOS) in 2d
@hollow crown Thanks for your help. For some reason when this is my code, it doesn't let me use the up arrow or W to enter the scene. But everything else works now.
Oh also am I supposed to @ you?
It's because you need to flip the logic, so the one that detects input is in Stay, and the other one is in Enter
It's all good because it's not just a random @ π
Great! We don't allow gifs though π
Oh sorry bout that. I should go read the rules. 
Hi everyone π , I would need your help if you have experience in gameplay programming for a design issue :
The situation : Iβm currently working with Unity, on a 2D platformer. I use the Unityβs built-in physics (Rigidbody2D and colliders) and I need to design a scalable system for the playerβs movements. Indeed, I want to easily add some mechanics or some series of movements (like long jump in Mario by crouching and jump at the same time).
How you can help me : If you have some references of similar systems or any idea of where to start I would love hear your tips.
Thanks !
okay i just have a question... does anyone know how they made the rotating in the original tetris on nes and stuff since im making a simple clone and thats the part im stuck on, and no i dont want to just rotate the piece. i use 64x64 boxes to make up the pieces
Anyone here have much experience with A* Pathfinding? im looking for a way for my enemies to ignore the player if they are outside the enemies pathfinding grid
Do you mean outside some sort of pathfinding range or in an unreachable position for A*?
Do you have a Rigidbody2d and Collider attached to your bot?
Well, the first things to check would be that you're moving the bot through the velocity of the rigidbody or with the MovePosition function. If you are, I'd make sure they level geometry and bot are on layers which can collide with each other in the Physics settings of your project
oh, and make sure that you are using BoxCollider2D's
so, i know this is going to sound stupid, but does physics.checksphere work in 2d?
no
There's a separate Physics2D class that has 2D stuff
ok, thanks
one last question, sorry, do character controllers work in 2d? or are they also 3d only?
3D only
ok thanks
Sorry i didnt reply to this sooner. I managed to fix the issue I was having. Thank you very much though
hey uh this is my code
whenever i right click I slow time and rotate the player towards the cursor,
then im supposed to fling them towards it
but it only shoots the player either upwards or downwards, with the speed dictated by the orientation of the x arrow
with it shooting me faster the more vertical the x arrow is
and frankly im fuckin stumped
Do you have any constraints on your rigidbody
maybe x position is locked for example
i do not
its a default rigidbody apart from the drag values
gimme ten im getting a coffee
man i can just not figure this out
after commenting this out the boost just isnt working at all
ah fuck man i give up for tonight
Hello,
I need to create a freezed lake, here's the upper layer of ice on the lake.
My ship must broke the ice layer, so I created multiple gameobject of ice layer which have a hinge join.
My question: How can I have the texture for each object to have a continuous look like the sprite above?
Is anyone here experienced with Playfab? (@me with response)
Some1 help a noob :3 i have a script for 2D game that spawns random blocks and they fall down and u need to dodge it. And the problem is i want to create a startscreen UI where i need to press space and then the blocks coming down i think i cant do that with an if statement? maybe some1 pm me who is good xD or to deactivate all the blockspawn.cs and the playermovement.cs till i press space and than it starts. i already have a Game Over screen with the seconds i achieved on it and when i press space it loads the scene(0) from new etc. now i just wanna make the startscreen right at the beginning when you start the .exe "Welcome to...game" your highscore is....press space to play
use a seamless texture
okay all my problems stem from these lines of code
i could add force instead but then movement feels like ice skating
how do I make movement feel less shit if i use force
so I am working on the movement on my game and I have a crouch disable collider but the problem is when is collide with something the collider gets disabled and it doesnβt even say crouching is true in my Console (I have a debug.log statement), the player kinda slows down a bit and the collider gets disabled just like itβs crouching but it says crouching is disabled
have you finished watching it?
but Iβm trying to do my own system
yes
I did everything like him but I changed some values
and added sprinting
idk why the collider is getting disabled
send the code then ill see if i can figure it out
Iβll send it in dms
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.
dont
oh ok
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.
How can i set the rotation from a child object in script
if i set the parent rotation to 0,0,45 then is the child rotation automaticly 0,0,-45
yes, i want fields rotate so:
(one square is on e object)
so i have first tried to ratote them at z -45
with paren work it but when i in code rotate the parent to 45, then it set all childs the z rotation to -45
and i can't edit the child rotation in the code
transform.rotation is the "world space" rotation
transform.localRotation is the rotation of the child relative to the parent
So, how do I remove sprite renderer from a certain object, but I would want to find that object by it's name.....
and later I want to add sprite renderer to the same object
I tried this: ```cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rendering0 : MonoBehaviour
{
public GameObject bg;
public GameObject fg;
public GameObject bg1;
public GameObject fg1;
public GameObject bg2;
public GameObject fg2;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Collision(Collider hit)
{
if (hit.transform.gameObject.name == "ColliderCubeThingy")
{
bg.GetComponent<SpriteRenderer>().enabled = true;
fg.GetComponent<SpriteRenderer>().enabled = true;
bg1.GetComponent<SpriteRenderer>().enabled = true;
fg1.GetComponent<SpriteRenderer>().enabled = true;
bg2.GetComponent<SpriteRenderer>().enabled = false;
fg2.GetComponent<SpriteRenderer>().enabled = false;
}
else if (hit.transform.gameObject.name == "ColliderCubeThingy1")
{
bg.GetComponent<SpriteRenderer>().enabled = true;
fg.GetComponent<SpriteRenderer>().enabled = true;
bg1.GetComponent<SpriteRenderer>().enabled = true;
fg1.GetComponent<SpriteRenderer>().enabled = true;
bg2.GetComponent<SpriteRenderer>().enabled = true;
fg2.GetComponent<SpriteRenderer>().enabled = true;
}
else if (hit.transform.gameObject.name == "ColliderCubeThingy2")
{
bg.GetComponent<SpriteRenderer>().enabled = false;
fg.GetComponent<SpriteRenderer>().enabled = false;
bg1.GetComponent<SpriteRenderer>().enabled = true;
fg1.GetComponent<SpriteRenderer>().enabled = true;
bg2.GetComponent<SpriteRenderer>().enabled = true;
fg2.GetComponent<SpriteRenderer>().enabled = true;
}
}
}
nvm, this won't work for other ways
I want to render out parts of my map that won't be seen from the current position of my character..... How do I do this?????
(if you can help me, please ping me, so I can see it.....)
you didn't call "Collision" anywhere. you probably wanted to use this https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html
I want to make the surrounding grid blocks bounce up like the one i click on, but delayed so it forms a wave-ish shape. how would i go about doing this?
Question! Here's my code. I need the frog that it's controlling to jump there and back, but it only jumps once and stops. Help! It's for a 48 game jam with 17 hours left so i need help asap please.
anyone have a idea how to make a simple plants vs zombies style building system? ive tried multiple tutorials but they dont do the trick
like drag and drop a item onto a grid
like what are you struggling with? which part? spawning objects? aligning them?
right now i can click, spawn in a dummy prefab and then when i let go of the mouse destroy it but thats as far as ive got
so not very far
kinda sounds like that's the bulk of it? what else do you want it to do?
make a build selection bar to choose which unit you wanna spawn?
well the things on the to do list are to make some sort of grid wether its in a script or just some gameobjects doesnt matter
then i would need to have the dummy prefabs im instantiating interact to build on the grid when i let go of the mouse
er.... well you can use the grid game object and use this code:
Vector3Int _gridPosition = _map.WorldToCell(_mousePosition);```
errr wait that might be the opposite, one sec
so that code would detect when my mouse is over the grid game object?
ah yeah this should convert grid coordinates to world position:
_UnderMap.GetCellCenterWorld(**grid coords here**)
and all of that would go in the update method of the grid gameobject?
well what you can do is click an area with the first code, and that would return the closest grid coords - then the second code would convert the grid coords back to world coords, which is where you would place the sprite or prefab or w/e
update and then check for the left mouse click input
ok
Yes, thank you!!!!!
ok so ive made quite a bit of progress but ive hit a wall
right now when i click on my gui i can drag a dummy around and when i let go of the button it deletes itself
there are grid objects that light up when im dragging said object around
i have a event on them that on mouse up will instantiate a prefab
but for some reason onmouseup doesnt work with dragging
i modified my code to not delete the dragging prefab and when i let go of the mouse i have to click again to instantiate the object
theres alot of code but i will post it
might be better to use a paste site for that amount of code
oh i cant delete the messages and resend it then
can*
there
thats what it does
can you instad of destroying the draggable instance, just drop it at the appropriate position?
What do you mean?
instead of destroying the instance attached to your mouse, instead just drop it? would that work in your case?
it gets destroyed because you are telling the code to destroy it
twice if i counted correctly
So deleta that and then see what happens?
well you could have to fix the position of the instanced object at some point, but yes, in general
I think Iβve tried that
when the code doesnβt deleted on mouse up
The object just sits there
is that not what you want?
Then if I click a grid space after I already let go then it places
No that isnβt what I want because the object on the cursor is just a dummy
you have a grid, use that code magic i sent earlier to get the center position of the individual grid cell and place the instanced object on that spot using the .GetCellCenterWorld() function. then in another array record spots already used
then if a spot is already used dont allow them to place a unit there
that's how i imagine i would do it
because that is how i do it XD
So then when I get the center I can instantiate the object then delete the dummy that follows the cursor?
why have a dummy follow the cursor? why not just have the object? you can do it your way, i believe that would work
maybe you use a dummy for performance or for a certain look
that'd make sense
Ok thanks for the help
look into the following commands:
_tempMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
_gridPosition = YOURGRIDHERE.WorldToCell(_tempMousePosition);
_SelectedGridsCenter = YOURGRIDHERE.GetCellCenterWorld(_gridPosition);
this is the magic you need for organizing/instancing objects to a grid
there might be a better way if someone more advanced than me wants to chime in, this seems somehow a bit inefficient, but it does work! π
do you guys encourage to use Physics2D.gravity to change the gravity or should I use something else
That's the only way to change the built-in gravity
does anybody know how to do custom gravity for a 2d game with the corresponding walk movement und jump stuff.. im really trying hard but im cant get it to work... It would be amazing If I could show the code to someone its a bit big for in this chat here.. so pls anybody hit me up
dont know how to explain my problem so heres a video
spot the 2 bugs and win a prize
this sometimes happens as well
except there he can move and not fall through and cant jump
tilemap thing
when i instantiate a object, that object has a script and i want to refrence a script on the object that instantiated it, how would i do that
var clone = Instantiate(whatever);
MyScript m = clone.GetComponent<MyScript>();
in my opinion it's better to just have whatever be a reference to your script type in the first place and then clone will already be of your script type
that is the opposite of what i want i think
i want the clone object to refrence the script that created it
Then you add one line:
var clone = Instantiate(whatever);
MyScript m = clone.GetComponent<MyScript>();
m.referenceToCreator = this;
does the rb.addforce just add force to the current one or does it overwrite it? (maybe its obvious but want to be sure)
It adds
If you want to overwrite it you would first do:
rb.velocity = Vector3.zero``` and then add your force
or just set the velocity directly to what you want instead of using AddForce
the end result of AddForce is always just to change rb.velocity
k thanks!
I'm going to be adding the input system to my local multiplayer game soon, and I'm wondering how I would make it so whenever a new player joins it sorts their collision layer?
Since I don't want the player bullets to collide with their shooter and accidentally kill them, I have 4 collision layers for each 4 players. And if the player was a prefab and is spawned using the input system or whatever, I presume it would stick to the same "player1" layer and the players couldnt kill eachother. is there any better way to do this?
or should i put this in the input system channel actually, i cant really tell.
Input system channel probably - but basically use the PlayerInput stuff. When your prefab spawns check your PlayerInput's playerIndex and set the layer accordingly
thanks for the quick reply! I'll try that out as soon as I can, and if it dont worky ill come back.
I changed it to : ```cs
void OnCollisionEnter(Collision hit)
{
if (hit.transform.gameObject.name == "ColliderCubeThingy")
{
bg.GetComponent<SpriteRenderer>().enabled = true;
fg.GetComponent<SpriteRenderer>().enabled = true;
bg1.GetComponent<SpriteRenderer>().enabled = true;
fg1.GetComponent<SpriteRenderer>().enabled = true;
bg2.GetComponent<SpriteRenderer>().enabled = false;
fg2.GetComponent<SpriteRenderer>().enabled = false;
}
else if (hit.transform.gameObject.name == "ColliderCubeThingy1")
{
bg.GetComponent<SpriteRenderer>().enabled = true;
fg.GetComponent<SpriteRenderer>().enabled = true;
bg1.GetComponent<SpriteRenderer>().enabled = true;
fg1.GetComponent<SpriteRenderer>().enabled = true;
bg2.GetComponent<SpriteRenderer>().enabled = true;
fg2.GetComponent<SpriteRenderer>().enabled = true;
}
else if (hit.transform.gameObject.name == "ColliderCubeThingy2")
{
bg.GetComponent<SpriteRenderer>().enabled = false;
fg.GetComponent<SpriteRenderer>().enabled = false;
bg1.GetComponent<SpriteRenderer>().enabled = true;
fg1.GetComponent<SpriteRenderer>().enabled = true;
bg2.GetComponent<SpriteRenderer>().enabled = true;
fg2.GetComponent<SpriteRenderer>().enabled = true;
}
}``` But it still isn't working.....
does anyone have any idea why contactfilter2d isn't working properly here? i feel like i've tried everything
{
layerMask = LayerMask.GetMask("Player")
};
print(contactFilter.layerMask.value);
RaycastHit2D[] rh2dRes = new RaycastHit2D[1];
Physics2D.Raycast(rigidbody2D.position, Vector2.down, contactFilter, rh2dRes, 5f);
Debug.DrawRay(rigidbody2D.position, (rigidbody2D.position + (Vector2.down * 5f)) - rigidbody2D.position, Color.white, Mathf.Infinity);
if (rh2dRes[0])
{
print(rh2dRes[0].transform);
print(LayerMask.LayerToName(rh2dRes[0].transform.gameObject.layer));
return true;
}
return false;```
How does your code, looks like this here?
what do you mean
any time I want send some codes, it doesn't look like this.
put the snippet inbetween ``` and ```
Oh yeah.
teleporting how to fix
in my game my bullet gets instantiated and then it goes foward, when it hits my enemy nothing happens
{
if(collision.gameObject.layer == 6)
Destroy(this.gameObject);
}```
i havent done a lot with collision but from how it seems, it looks like you check if the object it collides with is on layer 6 and if so destroy the bullet? i feel like this is a pretty obvious question, but what layer is the enemy on?
i think checking a tag might make more sense? tag all the enemies as enemies then look for a tag? if you'd be willing to show the game objects for a bullet and enemy (and all related properties) that might help. if you havent figured out your issue yet, that is.
yea i shouldve used tags from the start
tried to do some stuff with the collision matrix but it wasent ment to be
@topaz peak what does your code look like?
although it still doesnt work
i think ive done something wrong the colliders because i removed all the code from oncollision enter and just put a print(collision) and still nothing
if you'd be willing to show the game objects for a bullet and enemy (and all related properties) that might help. if you havent figured out your issue yet, that is.
thats the bullet
the things you cant see are the transform and sprite renderer
thats the enemy
that's alright not super worried about the renderer or transform
seems like you might wanna look into this function: https://docs.unity3d.com/ScriptReference/30_search.html?q=istouching
yeah sorry im not more help haven't used colliders that much besides detecting a mouse
still pretty new too
thanks for trying to help tho
it seems the problem was it being kinematic
i put it to dynamic and then put all the values to 0 and then it worked
both of the bodies?
uh that code is scary
I have this code that sets the camera to lerp between the mouse and player but for some reason as the character moves away from the mouse the camera becomes heavily off centered
How could I fix this
Even if i place the mouse on the player after movement the camera is still heavily off centered
If this is just a con im gonna have to deal with what are some ways i might be able to replicate the effect of the camera staying smoothly between the mouse and camera
Does anyone know why when I change the level using index, it just always takes me to the 0 index level?
show your code on how you're doing it?
I know this is bad but
that's the only way something works
one of them is on a trigger and another is for the ui stuff(canvas)
i'm confused on the flow, on what gets called where. Also take a look at this on how to post your code here
#π»βcode-beginner message
yeah so am I
so you're saying you put load the scene with the index of 2, but your scene with index 0 gets loaded instead?
yeah
every time
I've tried everything
this might have to do something with the code loading it twice, WHICH I KNOW IS Bad, but i just need to get it working
can i see your build settings
so you're trying to load Prototype2, but Menu gets loaded?
yeah
oh, so those are 2 different places you tried to load scene index 2. That was mighty confusing -_- those arent related?
honestly, no idea what's wrong at this point. are you sure you're calling that function that loads scene 2? Debug.Log to be sure
did you assign the correct function to the animation event? which is how i'm assuming you're calling OnFadeComplete()
I'll check everything, I probably have an idea why this is happening, thanks for the help
your levelToLoad is on different class, they are not connected
Is there any way to somehow make one script call a function from another script?
Yes
yeah but these tutorials don't help
do they not?
that's not the tutorial's fault
ill try tho
You can call other method like this: declare a object PlayerHealth playerhealth;
Then on Start() method: playerhealth.Getcomponent<PlayerHealth>();
And to use this method, you can just write PlayerHealth.(insert function name)
is there a way i can generate a 2d grid visually without spawning a bunch of sprites?
And make sure method you want to call is public, Sorry for miss information serializefield does not work on calling methods, only to show private method on inspector
can someone help me out? I need to this, but i don't know how i should aboard this
what is this?
its a work that I have to do to my university
yeah we can't help you with your homework. attempt it first. if you run into problems, you can ask like any other coding issue
but we will not do your homework for you
does anyone know how to make a 2d jetpack go up? but not like a jump.
like adding force to up
yeah blike getting progressivly stronger
like rb.AddForce(transform.up * someSpeed)
so it still isnt going up at all. I would show you my code but i cant type that much text here
You would call that every FixedUpdate while your jetpack is active
is there anywhere i can share large chunks of code here? because i read what you're saying i just don't know if i'm implementing it right.
https://hatebin.com/ @weary hull
Or https://paste.myst.rs if that one doesn't work for you
a powerful website for storing and sharing text and code snippets. completely free and open source.
it should be in FixedUpdate
also try increasing runSpeed
or multiply it with it's own variable
Has no tutorial online for one of the most common features of a game worked for you?
i tried to search tutorial online but they doesn't work
Hi, I want to make a 2d game. But i have aquestion. I have crosshair which is on the moouse position, but I want to draw a maximum range of the crosshair around the player. So when the mouse is outside of the range, the crosshair's position stops and rotates around the player on a circle
The blue gizmo is the max range, and the green gizmo is the "crosshair" which follows the mouse
Follow one to start with so we have a base to work from
ok
If you're having trouble with a specific tutorial maybe share the part you're having trouble with
the bullet does not move
You can solve this with Vector2.MoveTowards(playerPosition, mousePosition, maxRange);
Set the crosshair position to the result of that^
Don't be so ridiculous
ok
Just add "in 2d" to the Google search.
so it already follows the mouse, what i need now i whenever the mouse moves out of the blue gizmo, the crosshair should stop but still move around the player when moving the mouse.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCombat : MonoBehaviour
{
//Attack variables
public Transform attackPoint;
public float attackRange = 1f;
public LayerMask enemyLayers;
public int attackDamage = 40;
public float attackRate = 2f;
float nextAttacktime = 0f;
//build and break variables
public Transform buildPoint;
public float buildRange;
// Update is called once per frame
void Update()
{
if (Time.time >= nextAttacktime)
{
if (Input.GetMouseButtonDown(0))
{
Attack();
nextAttacktime = Time.time + 1f / attackRate;
}
}
attackPoint.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
void Attack()
{
Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);
foreach (Collider2D enemy in hitEnemies)
{
Debug.Log("We hit " + enemy.name);
enemy.GetComponent<ObjectHealth>().TakeDamage(attackDamage);
}
}
void OnDrawGizmosSelected()
{
if (attackPoint == null)
return;
Gizmos.color = Color.green;
Gizmos.DrawWireSphere(attackPoint.position, attackRange);
Gizmos.color = Color.blue;
Gizmos.DrawWireSphere(buildPoint.position, buildRange);
}
}
yes - I know. This code will do exactly that
They work. You haven't followed them properly. You're not making such a unique game that this problem is only specific to you.
this is my code now
@cedar stag
attackPoint.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
replace with:
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
attackPoint.position = Vector2.MoveTowards(transform.position, mousePosition, attackRange);
Thank you very much! I'm pretty new to UnityCS and it's pretty confusing sometimes.
Just had to change
attackPoint.position = Vector2.MoveTowards(transform.position, mousePosition, attackRange);
to
attackPoint.position = Vector2.MoveTowards(transform.position, mousePosition, buildRange);
How do I check collision between two layer masks?????
ah yeah sorry I picked the wrong one π
WDYM by this? You want to see if the two layer masks overlap at all?
Never mind, I did it differently
If so you should be able to do this:
int result = mask1 & mask2;
bool theyOverlap = result != 0;
alright
thanks anyway
Also, one more question, I want my projectiles to get deleted/destroyed when they hit my enemy..... They are all clones, how would I do that?????
I know how to check for hit
They need to have rigidbody2Ds and colldier2Ds
and then you can check in OnCollisionEnter2D or OnTriggerEnter2D for the collision
Thank you a lot.....
it's totally fine. I added another one, because I want the max range of the player being able to attack to be smaller then then range he will be able to build. So got that figured out now too
Hey guys π very new to Unity:
I have a bunch of ScriptableObjects (.asset files?) and I want to initialize and display them all when the game begins. What's the proper flow here? can (and should) I 'convert' them into GameObjects?
Display them how?
ScriptableObjects just hold data so is there some text or images or models you want to show in the game?
Yes π they're actually a bunch of card datas and they all have a Sprite which I want to display
(in a gird view, but I guess it doesn't matter)
To display a sprite in the game you need to create a GameObject with a SpriteRenderer and assign the sprite to that sprite renderer
You can do this all in script - or create a prefab that has the spriteRenderer and just assign the sprite in the script.
To do it all in script would be something like:
// create a GameObject
GameObject myNewGo = new GameObject();
SpriteRenderer sr = myNewGo.AddComponent<SpriteRenderer>();
sr.sprite = myScriptableObject.sprite;
If tis is a card game it may make more sense to make this thing intoa prefab and Instantiate it - then have a script on the prefab that has a function like SetMeUpBasedOn(MyScriptableObject so), and you call that to have the object set itself up based on the SO
this is a lot of pieces though - you'll need to take it slow as a newbie
try to get a single object created and displaying your sprite, then think about expanding that to do all the cards you want to show
Ohh ok I will try it out! thank you π
myReferenceToTheOtherScript.enabled = false;
Ok! Now I'm attempting a "dash" ability im trying to guess how to make it require 2 inputs "fire1" and a "horizontalMove" Input. I watched https://youtu.be/G3cGpnuzVHU to get an idea but he is using a detection instead of a second input.
Consider donating to help me keep this channel and website alive : https://paypal.me/supportTheGameGuy π
Support me on Patreon : https://www.patreon.com/the_game_guy
In this video im gonna show you how to make the player character dash in mid-air like the famous Hollow Knight game, You could make changes to the dash settings by playing around ...