#💻┃code-beginner
1 messages · Page 845 of 1
To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling
• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.
sorry if this is a wrong channel to ask this, but i need advice
i tried making multiple versions of a character controller for a 2D game that has moving as fast as possible as the main concept and the approach that felt the best was using transform.position += though i saw some people say that a rigid body would be better so i'm wondering if switching to it would really be worth it (despite the issues i had with it like movement on ground vs in air)
that really depends.. you can easily detect collisions also with just transform if you use rays.
how fast is it moving ? rigidbody can feel clunky if they are not tuned properly thats why most controllers are kinematic
If other physics objects should be able to hit the player and move them around (not just block them!), then you want a rigidbody
Put it on the asset store and post it in #1179447338188673034
(urgent, today)
sounds sus
how about if the only objects that physically interact with the player are walls and moving platforms?
@red moat This server is not for these sort of posts
Come on really
lol
...especially when it sounds like a scam
people love to just tell on themselves
like how lazy can you be to not even skim #📖┃code-of-conduct
hey im not rlly sure how beginner this is, but here's my problem:
im making uno (just as a personal project) and im trying to figure out how to assign the card sprites to the card values so that the correct sprites show on the screen. i already have the hands populated with cards i just am unsure how to go about my problem
Scriptable objects perhaps?
I would also go with SOs
With scriptable objects you can create an object with a color, pickup quantity etc
They will also allow you to store the card images
hm, ill look into this, thanks... but does that mean i will have to change all my object types?
They will also allow you to store the card images
yeah i saw this when i looked it up, p nice for my problem
right now i have my cards stored as a custom Card class
perhaps, I don't use them very often, but their essentially just a container
Yeah, so imagine your Card class, except you can create the cards before you press play, they will most likely have the same data
how did you do that so fast?? anyways...
haha UNO is a great project to do. Made this years ago
ah i see
but yeah ill look into that, seems very useful in general, thanks
hey all 👋 just joined
backend/devops guy here, also messing around with automation tools and indie projects
excited to see what everyone’s working on
basically they are tangible classes / object you can manipulate in the project / editor at edit time instead of runtime.
btw each one was created with a script with values assigned, just so you don't think you have to manually do each scriptableobject assigning enums manually all cards lol
CameraManager singleton? Or direct inspector reference to Camera?
I feel like Im falling into a common pitfall with the singletons
depends what needs it
simple DI goes a long way, not everything needs a singleton / manager
I have movement and camera logic split for single responsibility, character controller needs access to Camera transform to rotate the player transform to the Cameras current Y.
#🤝┃introductions & #1180170818983051344| #🏆┃daily-win
also check out #🌱┃start-here
I am most likely going to need a hard reference to camera for camera shake etc though, and I assumed the singleton would be better than 100 inspector references maybe.
Ive read a LOT of negative press about the singleton pattern though
its easy to abuse but they are not bad at all and pretty common pattern outside of unity
why do 100 things need camera reference?
Lets say I fire a missile at the player and it misses them, hitting the floor in front of them. I call CameraShaker ShakeCamrea(), CameraShaker needs reference to the camera
PlayerMovement also needs reference to the camera, for rotating the character
Maybe theres a cutscene system, that will also now need reference to the camera
the missle should only say " I hit something" then you can use events to fire a camera shake
so when would i use instantiate vs Scriptable Objects? or would i use them together? like ik instantiate is for when i want to spawn alot of the smae enemies in a plaformer or something. i used it once when i had to make a drivable tank for class.
thats only 1 script tho
UnityEvents? Dont those need to be linked up to work?
its not a Instantiate VS SOs thing.
they can work together, they are just not gameobjects so they are not spawned
they live within another object, like an asset.. think audio asset, a sprite asset etc
yeah, instantiate was just one of solutions i was looking at so i was just curious about the question in general
they are basically templates of data you can use
you're describing an apples-and-oranges comparison here
to "instantiate" is to copy a Unity object
ScriptableObjects are, indeed, a kind of Unity object
as are GameObjects, Materials, etc.
you spawn something,
the ShakeScreen manager or whatever Subscribes to events like the spawned objects event "HIT Something"
then spawned object fires that event on hit something,
ShakeScreen reacts to it with Shaking the Screen function
oooh bc instantiate creates the object in the hierarchy, but that wouldnt create the visual effect
oh
I think how it works is, you load the SO into a monobehaviour, the monobehaviour reads the data inside the SO, and does stuff with it.
For example, blank card monobehaviour gets the IMG from the scriptable object, and updates its card image property
if your sprites have predefined color/number already then SOs were mentioned to assign sprite to specific value/color
like I shown in SS
notably, this means that the card that your gameplay systems card about may not be a Unity object at all
I agree, it can be a helpful tool for explaining code or on how to expand it. I was touching on why we steer newbies away from it (until they learn the fundamentals) bcuz sadly, they don't do any of what you mentioned
It is a separate issue, but they lean on the LLM too much as an aide . . .
Wow, that is a good idea . . .
MVC is so cool
needed a card game without getting too complex and easy to pickup for others lol
who doesn't love uno tho
another really really good starter project I personally suggest is boids
boids are so cool
Oh, I meant YouTube for the C# fundamentals. That's usually the same across the board (give or take a few topics)
Some may have more than oyhers, but you can get a lot of the basics from websites . . .
Facts, I have Uno Attack. I should consider attempting to build it . . .
Sometimes some good old software design is needed
C# vids in Unity Context..mostly crap
C# vids in general C# context are the decent ones
Too much game jank suggested here
@upbeat pasture I may have implemented MVC without knowing, but I can't say I've properly/knowingly tried the pattern. Is that the same or similar to MVVM?
Id say so yes. I like the patterns as they teach you how to have logic and state separate from UI/visual view
I've never done programming outside of Unity, so I figured these patterns are more C# software development or Web Dev stuff (I think ) . . .
pretty sure MVVM is just controlling logic in the view right?
MVC MVP MVVM are pretty much all the same
They just all reference eachother differently
Like the MVP is basically jus the MVC but it references the model less?? If I remember correctly.
WPF flashbacks 😵💫
There are too many architecture acronyms
I like the PISS architecture personally
SOLID would like a word too
what's the architecture where you just make the game
i can't tell if i'm joking or not right now
When I started studying software arch I followed SOLID 100%, and it was just a headache
SOLID is a nice platonic ideal
I usually stick to KISS and SOLID . . .
learned most patterns through WPF (windows presentation form) and it was def not fun but It def speeds up a lot of knowledge
can't seem to find what PISS is supposed to be...
SOLID is a good idea until everything is abstracted and everything is also a subclass of a class
to be pedantic though these are principles not architectures
DRY's another one
though DRY is pretty good to follow
what is MVC? I keep thinking marvel vs capcom lol
model-view-controller
I wouldn't do all of solid but it's ideas are good
thats rough man
as Barbossa says, more like "guidelines"
should be able to google it though
I feel like there's a multi-player game with these acronyms as teams in the making
Each team solves the problem using their set of rules . . .
architecture is, like many things, better described with pasta shapes
just like nuclear pasta
theres so many ways to shave a cat 
You dont really need to worry about it in unity
not entirely accurate
Its more if you are making apps
By implementing common game programming design patterns in your Unity project, you can efficiently build and maintain a clean, organized, and readable codebase. Design patterns not only reduce refactoring and time spent testing, but they also speed up onboarding and development processes, contributing to a solid foundation that can be used to gr...
KISS vs SOLID vs DRY vs MVC/P/VM
Two groups are principles that utilize a bunch of different architectural approaches while the other two are specific architecture workflows . . .
Im just imagining all of my variables in the model
Even if they dont really belong there
isn't SOLID a group of principles rather than an architecture?
Oh, I don't like bloat . . .
damn i only remember SRP and Liskov substitution lmao
I guess that's more true, but some of the principles use a specific architecture and or pattern . . .
Isn't one of them injection or dependency or smth?
i don't remember the other 3, i should go check...
the "Liskov substitution principle" is just the idea that you can freely substitute B for A if B is a kind of A
Dependancy injection and single responsibility are the only two good ones to follow
and liskov
i.e. you shouldn't have derived types that fail in situations where the parent type does not
for example
if you have an Enemy class that has a Move method, you can't add a FlyingEnemy class whose Move method throws an exception if the enemy is on the ground
you've strengthened a precondition here!
which means that the user of the object suddenly has extra rules to obey
Single responsibility principle - there should never be more than one reason for a class to change. In other words, every class should have only one responsibility.
Open–closed principle - software entities should be open for extension, but closed for modification.
Liskov substitution principle - functions that use pointers or references to base classes must be able to use pointers or references of derived classes without knowing it.
Interface segregation principle - clients should not be forced to depend upon interface methods that they do not use.
Dependency inversion principle - depend upon abstractions, not concretes.
-# from Wikipedia: SOLID
Game Actually Exists 😉
I do not vibe with open closed
Is learning more efficient through hands-on experimentation with small projects and looking things up as needed, or are structured courses like GameDev.tv more important for building a strong foundation?
i have no clue what gamedev.tv is but if you want to learn youre best off following the official unity learning pathways
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Heavily depends on the person. I had to go around trying out stuff to see what worked with me the best. Personally, I lacked fundamentals to understand programming, and making small projects for game jams made me feel quite lost, even as I was learning. At the end I took this cool online course a few, and although I'm still a beginner, now I feel quite a lot more comfortable with code: https://www.edx.org/learn/computer-science/harvard-university-cs50-s-introduction-to-computer-science
And of course, there's also, art, music, sounds, etc. Same thing applies, find your personal way to learn
Hi, could someone explain to me why this doesn't want to work? What I'm trying to do is rotate the player to wherever their cursor is at
Vector3 screenToWorld = Camera.main.ScreenToWorldPoint(Input.mousePositionDelta);
transform.rotation = new Quaternion(0, screenToWorld.y, 0, 0);```
sorry for the snippet, but not sure if code this short is worth posting on pastebin
is that for 2d
you're trying to pass world positionY to a quaternion 🤔 doesn't make much sense thats why it doesn't work
quaternions values max out at 1 so they are not values you typically mess with without using the Quaternion functions like Quaternion.Euler
ohh
the basic gist, get the direction from your start point in world, to your worldPoint
get the direction. Pass that to the transform forward or rotation, something quaternion.lookRotation
or if 2D you can use that direction w Atan / Rad2Deg and, .rotation = Quaternin.Euler(0,0,angle)
so yeah Quaternion is not Euler angles
if it is for 3d you dont need to convert mouse to screenworldppoint
you need the mouse axis
we´d need more context
right now i'm just trying to make the character walk and look around. I've got it to walk, now I'm having difficulties with the rotation
if its like FPV thing then you don't need ScreenToWorld
look at the many examples on how other people do the camera
In most cases you're not looking at specific point through mouse pos, you're rotating the player/camera itself to look at specific point
once you get base knowledge especially all the components these are easier to build than they seem
(basically what nav was saying but explicitly) don't use new Quaternion, don't use rotation.x/y/z, they aren't values that would be intuitive to you unless you're a mathematician
i want to make an ability where the player generates multiple spikes coming out of the ground, how can i do that?
many ways to do this..which part are you struggling with?
to make multiple spikes come out of the ground
I get that but what did you try so far
lemme show you my script
oh wait before that
I created a movment script and everything works except for the jump and double jump
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[Header("Movement")]
public float moveSpeed = 8f;
public float jumpForce = 16f;
public float dashForce = 18f;
public float coyoteTime = 0.2f;
public int maxJumps = 2;
[Header("Ground Check")]
public Transform groundCheck;
public LayerMask groundLayer;
public float groundCheckRadius = 0.25f;
private Rigidbody2D rb;
private SpriteRenderer sr;
private float moveInput;
private bool isGrounded;
private float coyoteTimeCounter;
private int jumpsRemaining;
private bool isDashing = false;
void Awake()
{
rb = GetComponent<Rigidbody2D>();
sr = GetComponent<SpriteRenderer>();
}
void Update()
{
moveInput = Input.GetAxisRaw("Horizontal");
// Ground Check
isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, groundLayer);
if (isGrounded)
{
coyoteTimeCounter = coyoteTime;
jumpsRemaining = maxJumps;
}
else
{
coyoteTimeCounter -= Time.deltaTime;
}
// Movement
if (!isDashing)
rb.linearVelocity = new Vector2(moveInput * moveSpeed, rb.linearVelocity.y);
// Jump
if (Input.GetKeyDown(KeyCode.Space) && (coyoteTimeCounter > 0f || jumpsRemaining > 0))
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce);
jumpsRemaining--;
coyoteTimeCounter = 0f;
}
// Dash
if (Input.GetKeyDown(KeyCode.LeftShift) && !isDashing)
StartDash();
// Flip
if (moveInput != 0 && !isDashing)
sr.flipX = moveInput < 0;
}
void StartDash()
{
isDashing = true;
float dashDirection = sr.flipX ? -1f : 1f;
rb.linearVelocity = new Vector2(dashDirection * dashForce, 0f);
Invoke(nameof(EndDash), 0.18f);
}
void EndDash() => isDashing = false;
void OnDrawGizmosSelected()
{
if (groundCheck != null)
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(groundCheck.position, groundCheckRadius);
}
}
!code ⬇️ 📃 Large Code Blocks
📃 Large Code Blocks
Use links to services like:
https://pastes.dev/
https://paste.yunohost.org/
https://share.sidia.net/
https://paste.ofcode.org/
https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Hey guys
Hey I'm doing something a little out of my comfort zone and trying to make a ledge climb mechanic for my game. I'm trying to make it precise by calculating the distance between the hit point and the height of the actual mesh/ledge. This is my code currently, the player when the ledge detector ray hits a gameObject with the layer Ledge a second ray will spawn from the hit point of the first ray. I was trying to have it go up (Y+) by using transform.up. Instead I have the screen shot shown. I used more visible colors to make it easier to see in the screen shot
**
- Raycast From LedgeChecker gameObject (Blue)
- Normal Surface/Hit Point Second RayCast (Red)
**
private void OnDrawGizmos()
{
//Main Ray Detector
Gizmos.DrawRay(ledgeCheckerStart.position, orientation.forward * checkDistance);
//Normal Y Ray along Ledge Surface
float distance = (val.normal.y - val.point.y);
Gizmos.DrawRay(val.point, transform.up * distance);
}
private void FixedUpdate()
{
LedgeDetector();
}
private void LedgeDetector()
{
//Check for mesh with Ledge layer
isLedge = Physics.Raycast(ledgeCheckerStart.position, orientation.forward,out RaycastHit hit, checkDistance, whatIsLedge);
val = hit;
if (isLedge)
{
var obj = hit.collider.gameObject;
canHang = true;
}
else
{
canHang = false;
}
//Check find the distance between the hit point of first ray to the height of mesh to snap the player to that location
if (canHang)
{
float distance = (transform.position.y - val.point.y);
if (Physics.Raycast(val.point, transform.up, out RaycastHit surfaceHit, distance))
{
Debug.Log("HIT ALONG SURFACE");
}
else
{
Debug.Log("SPAWNED LINE ALONG SURFACE");
}
}
}
How can I make a raycast that is shown in the up direction instead of checking everything below?
Raycasts point in the direction you give it, they don't "default" to pointing "below".
So whatever direction you're applying, point it up. If you want it straight up regardless of rotation, use Vector3.up
The ray is still going down instead of up?
//Normal Y Ray along Ledge Surface
float distance = (Vector3.up - val.point).y;
Gizmos.DrawRay(val.point, Vector3.up * distance);
//Check find the distance between the hit point of first ray to the height of mesh to snap the player to that location
if (canHang)
{
float distance = (Vector3.up - val.point).y;
if (Physics.Raycast(val.point, Vector3.up, out RaycastHit surfaceHit, distance))
{
Debug.Log("HIT ALONG SURFACE");
}
else
{
Debug.Log("SPAWNED LINE ALONG SURFACE");
}
}
whats the value of distance cause if its negative you're doing * - which will flip it
since Raycast is only Vector3.up if you pullup the Physics Debugger you should see which direction raycast is going
im trying to parent the player to a moving platform so that the player can move with it but for some reason the player doesnt move with said platform. is it because rigidbodies arent fully compatible with parenting?
or maybe its just how i coded the platforms
unless kinematic , with dynamic rigidbody it wont work , when on platform you need to add the platform speed to the player velocity
im getting this weird bouncing behavior for vertical moving platforms. should i just add horizontal velocity then?
I'm trying to set a rigidbody's linear velocity inside a coroutine what I assumed would be every physics update (in this case theoretically making it so it travels forward indefinitely), but it's not moving what so ever. Why?
{
//For the time being just set it to continuously push it back
while (true)
{
print("Should be knocking " + name + " back");
GetComponent<Rigidbody>().linearVelocity = Vector3.forward;
yield return new WaitForFixedUpdate();
}
}```
is the rigidbody dynamic or kinematic?
It's definitely not kinematic
This is what the Rigidbody looks like at runtime and none of these values ever change
make sure the object isn't excessively big (since in that case moving 1 unit per second would be very small)
also make sure you've actually started the coroutine
The object is just a standard sized capsule collider
The debug message in the coroutine is playing, so the coroutine is definitely playing too
is the debug message printing continuously?
If I have it print the linear velocity before the yield return it gives me the right vector, but if I do it after the yield return then the vector resets to Vector3.zero (Very rarely it'll be the right vector, but it's very rare)
Yes
do you perhaps have anything else setting the linearVelocity?
Not for this object. This is the only script on it
...Wait
I think I know what the problem might be now
Ok. That fixed it
The animator was set to apply root motion
Unchecking it allowed the physics engine to actually affect it
Anyone knows why I get this error whenever I try to write a coroutine?
https://puu.sh/KNtJp/f8a88343ff.png
It fixes itself if I just copy/paste the word IEnumerator for whatever reason.
Still somewhat annoying
Iirc you need using System.Collections;
Currently it thinks you are trying to use the generic IEnumerator<T> from System.Collections.Generic
That does make a lot of sense
Hello ! I'm very new and I ran into this problem that I can't figure out :
I have an "Bar" in my HealthBar that I try to scale every frame between 0 and 1 with the healthPercent. Unfortunely, it doesnt update at all. The script works because when I input values manually, it displays the right ratio on load, but it doesnt update when unit takes damage. I dont know what I'm doing wrong.
You're updating the prefab, not the instantiated object
It needs to be something like this:
private HealthBar healthBar;
...
healthBar = Instantiate(...)
...
healthBar.SetSize(...)
also transform.Find("Bar") doest make any sense there , if you wanted to reference the bar GameObject you could simply use the inspector
Thank you to the both of you! I managed to make it work :)
!collab
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**
Also, this is not the right channel to write about this.
if you have a specific question, feel free to ask it here or in some other appropriate channel, like i mentioned in #💻┃unity-talk
Where can I send it?
are you looking for collaborators, or help on a specific issue?
Just help
then ask in a related channel #📑┃channel-directory
But here it says code-beginner
That's why I thought it would help
this is a code channel, this seems like an #🏃┃animation question if it's about IK
oh sorry
Guys how can I do:
A random objekt spawn only on x = -2 or 0 or 2
** My Idea was to make a random number from 1 to 3 ,
1 = -2 , 2 = 0, 3 = -2 ** is that right?
That will work, yes.
kk but is there any "better" way
If you want to be able to configure the positions in the inspector, you could pick a random value from an array
So make an array and give every slot like a position?
public List<float> positions;
then, elsewhere:
positions[Random.Range(0, positions.Count)];
this will give you a random value from that array
kk ty
consider what they mean in your situation.
if they're choices, use a list and index them
if they're dynamic values that you happen to have spaced 2 apart, consider using math to modify the range, eg you could do Random.Range(0, 3) * 2 - 2
(you can still configure this from the inspector with 3 slots - amount of values, spacing, first value)
Does anyone know how to calculate and find the remaining height of a cube from the raycast hit point. Im making a simple ledge grab mechanic?
I tried just turning off the gravity when colliding but then that messed up my player controller so I need to actually use raycast haha
ty
would recommend using something like coroutines rather than InvokeRepeating, but yeah sure
Havent learned that yet
okay so, why does this
_rigidbody.AddForce(Vector3.up * 30);
randomly either do nothing or launch my object stupidly far in an instant
object in question
how are you running that code? in Update?
it checks for key press in update
oh it seems that rubbing against cubes can also sometimes cause that
(I move the thing by setting linearVelocity)
if you set the velocity, the old velocity will be lost
applying a force causes the velocity to change
I keep the Y value during the setting and I also do horizontal movement before jump handling
okay, this is all kind of wacky
it seems that the object just fails to zero out its y velocity upon touching ground
so it stays on ground, but if I teleport it to y 60 it falls back in an instant
so you want this to be instantaneous?
in that case you'd pass a ForceMode of either Impulse or VelocityChange
are you applying gravity manually or something?
not really
and I don't suppose a gravity force of 30 is enough to break the engine
we'll need to see your code
using UnityEngine;
using UnityEngine.InputSystem;
public class Player : MonoBehaviour
{
public static Player Instance;
private Rigidbody _rigidbody;
private InputAction _moveAction;
private InputAction _jumpAction;
void Awake()
{
if(Instance!=null) Destroy(gameObject);
Instance = this;
_rigidbody = GetComponent<Rigidbody>();
_moveAction = InputSystem.actions.FindAction("Move");
_jumpAction = InputSystem.actions.FindAction("Jump");
_rigidbody.maxLinearVelocity = 10;
}
void Update()
{
ReactToMove();
HandleJump();
}
public void ReactToMove()
{
Vector2 m = _moveAction.ReadValue<Vector2>();
_rigidbody.linearVelocity = Quaternion.AngleAxis(CameraController.Instance.transform.localEulerAngles.y, Vector3.up)
* new Vector3(m.x, _rigidbody.linearVelocity.y, m.y) * 10;
}
private void HandleJump()
{
if(_jumpAction.WasPressedThisFrame())
{
_rigidbody.AddForce(Vector3.up * 30, ForceMode.Impulse);
}
}
}
after adding the velocity limit it would seem that the object maxes out on vertical velocity and doesn't decelerate
you're multiplying it's linearvelocity's y by 10 each frame?
couple of things. Physics movement should ideally be done in FixedUpdate.
(ForceMode.Impulse is fine in Update since its a once frame event)
Try to avoid Magic numbers like * 30
use variables like * jumpForce etc.
also they can be easily changed in inspector at runtime for tuning
oh I know, I'm just throwing a quick prototype, all of this is up for cleanup
If you just want the variables to be exposed in the inspector use [SerializeField] and make them private. Public should only be used when other scripts want to see the variable.
Here is a better visual representation of what I am trying to do. I'm trying to get the distance between the hit point and the top of the ledge height?
you probably need to query the collider upper half values
YPosition of Object + Half it's Y size is the position of the top. So just subtract the hit point Y from that.
caveat.. not all pivots start from middle, and scale on gameobject is a scalar so not accurate sizing,
collider will give you decent size values to work with
I'm just going off the diagram, he has the pivot at the center, and when I say size, what I should say is distance incase it's scaled as you say.
mhm
frankly if I were OP and this is a climb type mechanic I would do multiple queries.
1-2 to get get climbable wall, then check if it has at the top enough space for me to fit, so maybe do an overlap from there
something like this
This is the project I made a gif to show what is happening
I have 3 raycast and I'm trying to make sphere cast at each point so its easier for others to see the ledge detectors
The ray going upward is too long I need to calculate the hit point and the ledge height to make it precise
why do you need a ray going up anyway
Yes this will be climbable!
once you find the "ground" of the thing you want to climb, I would just do what I suggested. Check if the player can fit if he climbs, through the overlap cast
this avoids you trying to climb something that may have a low ceiling
By having a ray going upward from the hit point I can get the exact shape around the cube to find the top surface of the cube where our hands would go
That's why Im also making wire spheres to better keep track of everything
The red ray should stop when it goes above the surface of the ledge so that does need to be fixed
a hack way you can shoot another ray down to find the floor
From the player or the red raycast?
once the red ray moves up, as soon as it finds the ground(with ray shooting down from its end pos) it could perhaps move up until there is enough clearance for the player to climb
but you can also find the floor / part you need by querying the collider top part
there are also things like https://docs.unity3d.com/ScriptReference/Collider.Raycast.html
how would I go about keeping them from clumping up? adding a navmeshobstacle to each zombie just makes them trip out.
you need to start by separating their destination
vary their move speeds
vary their priority
they're all trying to move to a single point it makes it jank
I use multiple targets around the player, it keeps them from bunching up
most times if they are melee players, they try to encircle the player too..
this keeps it from being boring looking one direction for them
I currently am using Random.InsideUnitCircle so they all get a random point around the player, maybe I need to increase the circle size. Good idea on varying speeds and priority. I think that will help a lot.
yeah thats a good start. You also do some tricks where not all of them will go exactly where player is at first, depending ofc how "intelligent" you want them to appear. Also idk your game design but try not to make them spawn from the same spot / direction .. vary some where if player moves away not all of them start chasing player or at least not right away.
some randomness goes a long way
use verticality if your design allows, zombies that can also climb down / jump down to you or crawl from small floor spaces will add some spice
private Vector3 CalculateLedgeHeight(RaycastHit ledgeRay)
{
//Place holder variable
Vector3 ledgeHeight = Vector3.zero;
//Find the distance between the raycast hit point and the rest of the ledge height on the y leading to the top
float distance = ledgeRay.point.y - ledgeCollider.bounds.center.y; //???? Is this the right track
return ledgeHeight;
}
Thank you for all of the good ideas!
You're reversing the subtraction, and not taking into consideration the half height of the ledge object. It should be ledge Y center position + half Y height of ledge object (which will give you the y position of the top of the ledge), then subtract the ray Y position, so you get the distance between the top of the ledge and the ray.
private float CalculateLedgeHeight(RaycastHit ledgeRay)
{
//Represents y distance between raycast hit and top of ledge
float ledgeHeight = 0f;
//Calculate the position of the top ledge
//It should be ledge Y center position + half Y height of ledge object (which will give you the y position of the top of the ledge)
float ledgeYDistance = ledgeRay.point.y + (ledgeCollider.bounds.center.y/2) ;
//Get the difference (distance in between)
ledgeHeight = (ledgeYDistance - ledgeRay.point.y);
Debug.DrawRay(ledgeRay.point, Vector3.up * ledgeHeight, Color.red);
//Create A Raycast to find the top of the surface
if(!Physics.Raycast(ledgeRay.point, Vector3.up, out RaycastHit hit, ledgeHeight))
{
}
return ledgeHeight;
}
I get the feeling I might be close but there is something I'm missing to make it the right height
//Get the difference (distance in between) ledgeHeight = (ledgeYDistance - ledgeRay.point.y) - step;
can't you do something like this?
var raycastHit = Physics.Raycast(
transform.position,
transform.forward,
out var rayHitInfo,
1.2f
);
if (!raycastHit) return;
hitRay = rayHitInfo.point;
topCollider = rayHitInfo.point;
topCollider.y = rayHitInfo.collider.bounds.max.y;
var startTopPos = topCollider + Vector3.up * charHeight;
var someOffsetFromEdge = 0.12f;
var frontHitPosIn = -rayHitInfo.normal * someOffsetFromEdge;
startPos = startTopPos + frontHitPosIn;
var colRay = new Ray(startPos, Vector3.down);
var hitCollider = rayHitInfo.collider.Raycast(
colRay,
out var colRay_HitInfo,
3f
);
if (!hitCollider) return;
// the spot where we want to climb probably?
//colRay_HitInfo.point```
its kinda hack but might work
you can fix magic numbers tho
I used something like this in the past, but the requirements weren't too strict, and was dealing with easy primitives
@still ingot
there is probably a simpler way but my brain today aint havin it lol maybe someone else has a cleaner more mathy way
Not gonna lie this looks cool. Like your in animal crossing placing down furniture haha.
gizmos r fun
This works a lot better for checking the height of the ledge from the hit point!
k.i.s.s. principle at its best lol
You have a mistake in the code here. float ledgeYDistance = ledgeRay.point.y << (this should be ledge object position.y)
which one
Did you fix the mistake?
I actually used @nav example added a debug ray from the top ledge corner!
private float CalculateLedgeHeight(RaycastHit ledgeRay)
{
//Represents y distance between raycast hit and top of ledge
float ledgeHeight = 0f;
//Get the top height of the mesh
Vector3 topCollider = ledgeRay.point;
topCollider.y = ledgeRay.collider.bounds.max.y;
//Top point Y of the mesh
var startTopPos = topCollider + Vector3.up * ledgeHeight;
val2 = startTopPos;
Debug.DrawRay(startTopPos, Vector3.up * -0.1f, Color.red);
//Disable wiresphere
if (!isLedge)
val2 = Vector3.zero;
//Create a forward Raycast
if (!Physics.Raycast(startTopPos, Vector3.up, out RaycastHit hit, -0.3f))
{
Debug.DrawRay(startTopPos, orientation.forward * 0.1f, Color.red);
}
return ledgeHeight;
}
I think the fact that I wasn't really getting the colliders bounds was the reason why it was difficult
float ledgeYDistance = ledgeRay.point.y + (ledgeCollider.bounds.center.y/2) ;
//Get the difference (distance in between)
ledgeHeight = (ledgeYDistance - ledgeRay.point.y);
If you look at that too, you'll see that you're adding and subtracting ledgeRay.point.y, so that will cancel to 0, so the ledge height will always be (ledgeCollider.bounds.center.y/2)
I added more on to the function which snaps the player to the hanging location. I tried adding offsets to help keep the player from merging into the ledge:
///////HANG ON LEDGE AT LOCATION BELOW///////
//Create a forward Raycast
if (!Physics.Raycast(startTopPos, Vector3.up, out RaycastHit hit, -0.3f))
{
Debug.DrawRay(startTopPos, orientation.forward * 0.1f, Color.red);
isHanging = true;
}
Vector3 hangLocation = new Vector3(startTopPos.x, startTopPos.y + offsetY, startTopPos.z + offsetZ);
if (isHanging)
{
transform.position = hangLocation;
rb.useGravity = false;
playerObject.enabled = false;
}
guys, i need some help, for some reason script is not working
like... its actually not working, even debugging with Update does absolutely nothing
script is monobehavior, everything was added into the object
Try making a new script and testing that out with debug logs
Then if it works port over the code from the original to test again to be sure its not your code as well
for some reason that actually worked but now theres another problem
why OnMove() is not working?
depends which mode is set on the PlayerInput component
thats not what I said, thats not a component
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.5/manual/PlayerInput.html
easy to google what I mentioned
@rapid stump
Yea that component is what can do the "magic call a function for an input action"
what?
.wanna join my dev team
don't randomly tag people its against server rules #📖┃code-of-conduct
im not that advanced on unity rn 😭
i can do other stuff but i have no time
not the best channel to beg for team members in id say
and not the best candidate ngl
anyways, thanks, thats actually worked! 🥺
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**
Sorry wrong person
its okay
@shy verge #💻┃code-beginner message
I'm a builder tho
Not a place for recruitment. Read the bot message.
!code
📃 Large Code Blocks
Use links to services like:
https://pastes.dev/
https://paste.yunohost.org/
https://share.sidia.net/
https://paste.ofcode.org/
https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
https://pastes.dev/ikynHgvNi5 trying to add a limit but it freezes my unity instead
the while there will keep looping within the same frame
since transform.position isn't changing, this will be an infinite loop
keep in mind that Update is already a loop that executes once per frame. you may want an if instead of the while, or consider using coroutines
also the first condition in the while is covered by the second one
adding limits at -2 and -7
if you want it to be between those values, you would need <= -2
i guess you want || then if you want -2 or -7
Hello, i want to install the webgl module for unity 6000.3.6f1 and then build, why i dont see an option to install here?
hey im not an good coder
how do i make this goal spin around the circle but make it stay in the middle of the line? please help me out
Put the goal's pivot point in the middle of the circle and then rotate normally
alternatively rotateAround the middle of the circle
let me tryt
this might be a dumb question, but i'd assume that running new some_class() 100x in a single script is a significantly less strain on the computer than having the script class being put on 100 different objects?
It's unlikely that there's any measurable difference. The choice should be based primarily on other things than performance
.. this
If it does that then either the pivot point is wrong or the code that rotates it is wrong
ok
let me try
is therre any other wayt
is ther any other way to make it spin like how i want it
they told you how
im so bad at coding
you don't even need code for this
huh
its basic parenting in hierarchy
im very new in unitt
It's done the same way no matter if you're very new or if you have 20 years of experience
put the goal as child of the circle, move it to the edge where it needs to be, rotate the parent circle
Bro every time i move my camera in scene my pc is having a stroke
And my pc isnt even using like 20% of its gpu or cpu
Hey, I have been trying to make my own ledge grab, and right now mine is constantly flying upward and not staying in the hang position. What am I doing wrong?https://pastes.dev/MuAtx32tD3
Hello does any1 know how to get these type of ball phsics https://youtube.com/shorts/yvqsN3EiEFE?si=hJQ2Ca2LmSql0e0q
Step into the electrifying world of 2D football simulations, where neon footballs collide in thrilling arcade-style matchups! ⚽✨ Our videos feature captivating football simulations across the biggest leagues like the Premier League, La Liga, and Champions League. 🏆🌍 Witness neon footballs bounce and battle with stunning visuals that co...
Can't figure out any other channel to ask this in, but...
Does anybody have or know of a workaround for the 15 diffusion profile limit in Unity 6.3 LTS HDRP?
i do
What's the workaround?
Here is the code I added for my ledge climb script. Now the weird thing that's obvious in the clip I shared is the player will be shifted based on the offset that's great, but its not what I want. I want the players forward location to be offset by the ledge its facing. Also is it possible that I need to make the player a child of the ledge?
Vector3 hangLocation = new Vector3(startTopPos.x + offsetX, startTopPos.y + offsetY, startTopPos.z + offsetZ);
if (isHanging)
{
transform.position = hangLocation;
rb.useGravity = false;
rb.linearVelocity = Vector3.zero;
playerObject.enabled = false;
}
Anyone know why if two people are working on the same project shared over github and both people have active input system set to 'both', one person would be able to use the unity old input system and new input system in tandem but the other person would only be able to use new input system?
perhaps the input backends have not been reinitialized
Hmm OK I'll look into that
try cycling the active input handling, eg set it to something else and set it back to what you want
do u guys just add an extension for camera? geez I was suffering on making my own and turns out there's cinemachine
the drag rotation is kinda tricky
cinemachine use is very standard yes
To some extent you just slowly pick these up but searching something like "unity limiting value between min or max" or etc. would probably lead you here
and if you go back a page there you can see mathf has a ton of handy functions https://docs.unity3d.com/6000.4/Documentation/ScriptReference/Mathf.html
i ran into a problem yesterday where when i added a network object and network transform to my character controller in unity that when it jumps it will jump forever, like it never detected leaving the ground and was caught in a loop, i have a cloth sim for his jacket - just wondering if it thinks the ground is the cloth colliders for his legs? Just using the third person controller asset
Without seeing code, we can't see how it works.
it was the thirdperson controller from the starter asset - i dont think I'm allowed to share it
You can show the code.
i think i fixed it, i think it had something to do with the way i reordered the prefab and had some hidden duplicate controller or something wierd, thanks anyway
guys if i just want the mesh collider to work properly i should always make it convex right.
Yes and no. If you want it to be dynamic, it must be convex. For static colliders (no active rigidbody), non-convex is totally fine
hmm k , also is it possible for me to view the mesh collider?
With the Physics Debugger I believe so. Outside of that, I'm not aware of a way
I guess Unity thought the mesh would usually just reflect the rendered mesh so there wouldn't be a point in visualizing it
yeah but since there is a diff between a concave and a convex mesh , should visualizing it be helpful on what to choose in certain scenarios
How would it be helpful though? You see the mesh no? Unless you are using a different mesh for rendering and for the collider...
and its on btw , but i can't see mesh colliders, i can see the other normal collideres like box or capsule
ok so ig i should assume that convex collider doesnt consider holes and other stuff, else it fully fills the material
hi
i have a question what tutorial should i watch on youtube? iam complete beginner in c# scripting
oh wait are you not seeing convex colliders either? Normally you would not see concave mesh colliders but convex would show like other colliders
yeah exactly lol
for c sharp??
yes
well you can find some all in one basics video and understand how C sharp works. Tbh that is enough.
oh alright thank you for replying
Do you have MeshColliders disabled from here?
one sec lemme check
ok where is that ???
On the scene view, top right maybe if you haven't moved it?
You need to have the view options enabled though for it to be visible
it was at the bottom for me .
there are resources pinned in this channel
for what purpose, exactly..?
to show if is it good
But do you have mesh colliders visible on the gizmos visibility view?
well no-one's stopping you but you aren't necessarily going to get answers about pros or cons
sort of outside of unity but does anyone know why visual studio sometimes just won't find code that clearly exists? Here it is not finding the exact string im staring at 
What are you even trying to search for? Post a screenshot which has the the whole search window
is that in the game view?
Oh sorry, the error message has the string I was searching for in it, I was searching under "entire sollution" because none of the options yielded any results despite me knowing that exact string exists
this was yesterday so I dont have VS open in front of me now
Scene view, the first screenshot I sent, you need to click the downwards pointing chevron/arrow
yooo i can see it
thanks a lot gang
see what? the mesh colliders?
yeahhhh
i just had to turn it on thats it lol
nice, you are welcome
eyy wait one more sec
in this excercise im trying to do from "learnunity.com" , the top plane and the cylinders get thrown upwards when i start the game. Everything but the bottom plane has rigid body and all of the meshes have a mesh collider. Why is this the case bruh.
Can you show the Physics Debugger?
I don't need that, I want to see the scene which shows all the colliders at once
how do i do that?
You need to enable this #💻┃unity-talk message in scene view and enable everything from the Filtering section
where is dis?
Should be somewhere in the scene view
cant find it lol
it's only there when the Physics Debugger window is active
hmm k
@everyone I need Help, How to use smartphone keyboard to type something in an input field on Unity WebGL Builds ?
Please I desperately need help I'm not understanding why my code is not working. Here is the code I added for my ledge climb script. Now the weird thing that's obvious in the clip I shared is the player will be shifted based on the offset that's great, but its not what I want. I want the players forward location to be offset by the ledge its facing. Also is it possible that I need to make the player a child of the ledge?
Vector3 hangLocation = new Vector3(startTopPos.x + offsetX, startTopPos.y + offsetY, startTopPos.z + offsetZ);
if (isHanging)
{
transform.position = hangLocation;
rb.useGravity = false;
rb.linearVelocity = Vector3.zero;
playerObject.enabled = false;
}
no need to tag en entire server for this.. Luckily the command is disabled..
Anywho..
have you tried manually calling TouchScreenKeyboard.Open ?
https://docs.unity3d.com/6000.1/Documentation/ScriptReference/TouchScreenKeyboard.Open.html
if y'all were to create a spawner of enemies (such as minecraft natural spawning), would y'all do so by using prefabs with monobehavior scripts attached to them, or with a monobehavior script running in the background that inserts all the prefabs into a list and does a function for each of them? i was gonna go with the first option as it seems more straightforward, but will it significantly impact performance?
Personally I'd do the former, but I'd use Pooling for sure
Each enemy prefab would have a Monobehaviour script (if that's what you mean) . . .
okay, thanks, pooling, as in spawning the items before they're needed?
yeah, that's what i meant, i was thinking of one big script that controls all of them
But yes, you can pool them from a list . . .
You can give them a tag and put them under an empty GameObject. Then attach the MonoBehaviour script only to the parent object
and in the script check if the objects have that tag and move them however you want
pooling as in recycling the old enemies so you don't have to keep instancing new ones
whether or not 1 script controls multiple enemies vs each controlling themselves thats more of a design question.
okay thanks
ima attach it to a prefab and then spawn them int
That works as well. You'd have a MonoBehaviour script containing a list of all the prefabs you can spawn (for that specific level/area) . . .
okay, i'll do that, and have another script in each of the prefabs to control its behavior, thanks!
can I assign a prefab to a variable in code?
ofcourse
Prefabs are nothing special, they are just regular gameobjects
in most cases you want use a component directly on it if you have any besides the Transform one.
I'm making a SO for each character that contains a reference to the prefab to spawn later, how do I assign that?
just drag into it like you would any asset
so I can't do it in code?
You can do anything in code you can do in GUI
you can do anything in code, but that doesn't mean you should
var thePrefab = //grab this however you like if not inspector, Resource, IO etc..
mySo.SomePrefab = thePrefab```
also true. Is there a specific reason you can't just drop the prefab in SO ?
for character SOs? i don't think you would want to do this in code
there will be a lot of different SOs so I'd have to open up each one and drag and drop the corresponding prefab into each one individually which would be a lot more work than writing the path to the prefab in code or however one would do this
What's the current sample size?
currently 32, possibly more later
you could have a serializeddict as an editor utility for this, probably
what's that
Referencing from the inspector is part of the level/scene design. So by explicitly setting the field, you're certain that those SOs exist and that those fields are populated. Dynamically assigning the fields during runtime will not ensure any element, so do be aware that there is potential for undefined behavior. Populating the inspector using an editor function is perfectly fine as well, if you're wanting automation.
which part?
what does 'serializeddict as an editor utility' mean?
it's not really dynamically set, more like hardcoded from the start
Right.. so if hierarchy changes or new paths are added... expect stuff to not work. Debugging hell for the future you or others (paths may be incorrect, items may not exist etc).
and if I drag and drop and change things around it'll keep track of everything?
Context menu for automatic population in the editor; to bypass redundancy.
You would access your function by right clicking on the component and selecting the context menu function you created to execute the function.
I don't really know what you're talking about now
you could have a utility script/menu/etc for use within the editor, exposing a serialized dict for you to drag stuff into
ok idk what any of that means so forget about that, I'll just drag and drop if that's how it has to be done in unity
how do I add scriptable objects to a list?
same thing
either inspector or code
the process doesn't' change, SOs are assets, Prefabs are assets, Sprites are assets etc..
for example, I have a scriptable object called LiskarmConfig and I'm trying to do something like private List<ScriptableObject> characterConfigs = new List<ScriptableObject> { LiskarmConfig };
but it tells me I can't use the class name in the list
it's something in your code
ye
You don't have a type named Player
but what
at least not in that assembly
It's telling you that it doesn't know what Player is
how do I add the object if not like this?
im tryna learn so i might be a bit stupid i followed a tutorial
this is the tutorial
its like 7 years old so somthing might be old
this is the bottom
you cant pass a class name directly into a collection initializer because the compiler expects an instance of an object, not a type blueprint, fixing the "Class name is not valid at this point" error in Unity, you must either reference an existing instance or instantiate a new one
where is you Player class
i dont know :(
but its just a SO with some character config, not something I can instantiate
im so confuzled
Player player;
implies you have Player class in your project
unity has a special method for instantiating SOs
im noticing a discrepancy between class names from you and the tutorial
thats the tutorial
so im going to assume you named your "Player" class something else earlier
no
or ima check wait
theres one from the packages
but if i click the error it sends me to this one
can you link the tutorial you are watching please....
alright
new List<ScriptableObject> { ScriptableObject.CreateInstance<LiskarmConfig>() };
We'll make a Top Down Character Controller from scratch in Unity. We'll use the raw Controller Inputs to implement our Character's Movement and Animation. We'll use nested Blend Trees to easily handle all 8 directions with different speeds. We'll also cover topics like Sorting Order, Inspector window's headers, and Colliders.
Are you interested...
ok I think it's not going to work this way because I might need multiple instances, what's the best way of keeping a list of configs without instantiating?
cursed
you didnt watch any tutorial before this?
this tutorial is obviously a part 2 or 3 of another tutorial
wait what is your goal eactly
you can drag assets into a serialized field and access the mwithout isntantiating anything
im sure you experienced unity folks have a ton to teach me im coming from c# and full stack dev lol
so for each character I have an SO containing a reference to the prefab to spawn, and this is for a multiplayer game. so the goal is, when someone picks a character, the game takes the list index of the list of SOs, sends it to the server, and the server picks the SO from the list using the index and spawns the prefab referenced within. If multiple people pick the same character, they will need separate instances of it though
have tried fixing this for way to long, no matter what I do it takes me back to this error, can someone help me
nah it can be valid in certain circumstances but when possible the inspector can squash doubts better
did you save and did it compile ?
oh wait..
yeah
this is a classic unconfigured IDE/Editor issue
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
do you have a class named Monobehaviour
no?
MonoBehaviour
so...as far as what i know..the best way to do this is a character data so to ensure the character configs inherit fro ma base class OR simply contain hte data
but youll need a single source of truht for your character database
sometimes when i reload it, it is..
c# as 98% of languages, is case sensitive
both the server and the client will look at the characterdataabse list because the list order is the same for everyone
MonoBehaviour, not Monobehaviour
honestly is there one that isnt case sensitive lol?
sql
one more
and when your server reciegvse the index, it instsantiates the prefab inside of it. always creating a unique separate instance of that character.
Your ide isn't configured. Folks are supposed to redirect you to configuring your ide to prevent simple unwanted spelling/syntax mistakes.
il be back in 2 days with a horrible stupid problem
oh damn you right
to be fair writing sql feels like youre basically screaming the entire time lol
half the shit is in all caps
@silver fern does that help
-# also shells kinda for some things if you're on a case-insensitive fs, but arguably that's not the language being case-insensitive
bash 🤮
a couple including SQL , Fortran, BASIC
do you have any other errors in the console?
no
I'm... unsure
honest question: have you made games before?
this would still be configured if its not underlining red and you dont have such a class named Monobehaviour
the other's are right though your ide isnt configured so bugs aren't showing
yes but not with unity
i only ask because you're gettijng into async stuff
and wanna make sure we're on the same page
and also not online
yes, you should have a single source of truth for most things.
how do i configure ide
!ide
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
as far as I can tell I don't have multiple
@silver fern especially for mp games, this is true
you should definiteyl have a "Source" object
so essentially it will contain hte data needed that both the client and the server can see
thats the prefab
on somewhat related note, check out these new features in VSC I just noticed
(gameobject in the serializefield is shown in editor)
the characer prefabs contain all the information relating to the characters, but I need a list of them
think of it this way: you have a book titled "Multiplayer Game", in that you have a chapter. the chapter describes only the characters in the book. the rest of the chapters use those characters from that chapter to buil the rest of the story.
why do you have SOs then?
they have to persist across scenes
prefabs persist across scenes, their instances might not
prefabs are assets just like SOs
idk I was told to make SOs to do this
are the prefabs for each character structured differently? eg they have different child objects/hierarchy setups
i already got these tho
@silver fern https://dev.to/snowman647/single-source-of-truth-d29 check this out
if not, you could consider making it so that the data is all on the SO, then you would only have 1 prefab that reads the data from the SO and does stuff appropriately
Restart Required
I don't think that is possible because of all the different sprites and animations and whatnot that are different for each character
i'm willing to bet this was ai generated ~_~
i had them before all of this.
you can have an AnimatorController in the SO
shrug if it has good information
have restarted 23million times ATLEAST
ok, have you installed .NET from the .NET install tool?
tried, didnt let me, can try again
if it doesnt you can always manually download SDK
just reboot pc after
sure, if it still "isn't letting you", please elaborate on what the issue is
(also, once it's installed you'll have to restart vscode)
what I'm trying to do is make a character selection menu that will tell the server what prefab to spawn in the next scene, basically
ok? that doesn't go against what i suggested though
I don't know how to do that and it sounds like something that will cause me to end up in an unfixable mess again
You should try to reverse it, the server should make all the decisions, and the player should do simple things like send input to the server.
ok but how do I tell the server what prefab to spawn then?
If you have a list of spawnable prefabs, the player can send input, left arrow, right arrow to the server, and the server can change the index of the selected prefab.
that is gonna cause too many problems
if an input is dropped its an immediate desync situation
sure, we can go back to what you had before with separate prefabs.
what's the SO defining? just the prefab?
installed it, restarted unity, still same error
In the long run, the more decisions the client side is making, the more prone to cheating. The server should be the truth, and the clients just predict a little, then correct.
yeah right now it's really just the prefab
then the SO isn't really doing much, you can just use the prefab reference instead
what error? also restarting unity is not any step in this
Anyone looking to join a team?
!job
There's no command called
job.
whoops, wrong server for that command
!collab
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**
the other issue with that is that in that case the server would have to simulate every client at the same time in different states and it would be way too slow
Oh ok
derive from monobehaiour when trying to add the script
that's what you're trying to do. what's the "error" you're referring to
note that configuring your ide is not supposed to fix errors
it is to let your ide help you fix them
Is there any severs for builders and coders chris
the issue right now is that the error/mistake isn't being highlighted within the ide, which is what configuring the ide is supposed to fix
builders and coders ?
okay
This is how professional multiplayer games with dedicated servers work. Getting something working is probably more important to you at this stage than thinking about cheating and things like that so I understand.
Like devs looking for teams other than this server
places like The Coding Den I think
thats for people who have a lot of money to run powerful servers
Link?
Try any of the other unofficial unity discord server, other social media platforms etc
Idk how to join there server
well i downloaded the .net and it still does not highlight
Dms
You don't need to use dedicated servers to implement these methods though. Any multiplayer game working with host/clients can work this way. Usually, clients send signals to the host, and the host sends signals out to every client. It's not slow, it's standard.
discord.gg/code
this will be a free p2p game without dedicated server so it has to be able to handle 10 clients while running on a toaster
pretty sure if you google these you find them
also GMTK etc.
@naive pawn
did you restart?
yep
have you restarted vscode? (also to make sure we're on the same page, this is from the .NET installer in vscode, correct?)
type dotnet --version in command
no need to ping me again.
ye
I got in it how should i recruit people?
I want to make a turn based RPG UI system for a 2d game but every tutorial I find uses canvas and I want a system where the UI is part of a character in the game moving through papers attached to them, with one option going to an inventory with a grid system. My questions are how can/should I move through the papers changing their sprites avoiding two being selected at once due to button mashing/lag and how can I make a zoom in/out to an item on the screen (bag that opens to reveal the grid system) avoiding the zoom to get stuck or permanently changing the zoom in the screen.
typically you offer money for services, so start with that
Ik but they could make money off of games with percentages if the game does well
lmao
Be convincing.. money is a great incentive.
would you rather work for a. money or b. a promise of money
reasonable people choose a. and laugh at anyone who suggests b. 
Hey does anyone know what's wrong with my I got my player to finally enter a hanging state but it seems to face the wrong direction? I coded it to face the normal of the ledge but that seems to not be working?
private float CalculateLedgeHeight(RaycastHit ledgeRay)
{
//Represents y distance between raycast hit and top of ledge
float ledgeHeight = 0f;
//Get the top height of the mesh
Vector3 topCollider = ledgeRay.point;
topCollider.y = ledgeRay.collider.bounds.max.y;
//Top point Y of the mesh
var startTopPos = topCollider + Vector3.up * ledgeHeight;
val2 = startTopPos;
Debug.DrawRay(startTopPos, Vector3.up * -0.1f, Color.red);
//Disable wiresphere
if (!isLedge)
val2 = Vector3.zero;
///////HANG ON LEDGE AT LOCATION BELOW///////
//Create a forward Raycast
if (!Physics.Raycast(startTopPos, Vector3.up, out RaycastHit hit, -0.3f))
{
Debug.DrawRay(startTopPos, orientation.forward * 0.1f, Color.red);
isHanging = true;
}
//Stop the gravity and freeze the player speed and cancel jump animation
if (isHanging)
{
rb.linearVelocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
transform.forward = ledgeRay.normal;
rb.useGravity = false;
move.jumpButtonPressed = false;
playerObject.center = new Vector3(0f,0.5f,0f);
transform.position = new Vector3(transform.position.x, /*transform.position.y - */((ledgeRay.collider.bounds.max.y /2)), transform.position.z);
}
else
{
playerObject.center = new Vector3(0f, 0f, 0f);
}
return ledgeHeight;
}
you can try closing VSC go into UnityEditor under Preferences -> External tools and do Regenerate project Files
it might not work properly if you have compile errors though so may be why
fix the typo first if that clears compile error , try again checking if underlines error or offer suggestions
don't modify the transform, use rb.position/rotation if you want it to teleport while still keeping sync with physics
Log the normal and your forward. Also, I'm not sure if Transform and RB will play nice with one another.
still looks the same
Not as in I want the exact code btw I'm asking for the logic of it
Like a recommended approach to avoid problems
what typo?
Monobehaviour instead of MonoBehaviour
it is with a small b
no underline
we know it was... we're saying that part of the "typo"
Maybe they've got the incorrect deprecated vscode package
huh
oh?
right so have that as MonoBehaviour, restart vscode/regen project files, see if it compiles and configures itself correctly
(eg afterwards, write Monobehaviour and see if the ide reports the error)
now it does not correct
what about random errors
did yu do the regen project stuff ?
wat happens if you ctrl + click the Monobehaviour ? does it take you somewhere
yeah
nope
ok so if you didn't somehow accidentally create a Monobehaviour class.. its still not configured proper
okay... hmm
any errors in the Output tab of VSC?
nope
It's https://docs.unity3d.com/ScriptReference/MonoBehaviour.html
Nevermind it's mentioned above, ignore.
I made a SO containing a list of prefabs, I think that should work
using UnityEngine;
public class CameraCollision : MonoBehaviour
{
public Transform target;
public Vector3 offset = new Vector3(0, 2, -5);
public float smoothTime = 0.3f;
public float collisionRadius = 0.5f;
public float minDistance = 2f;
public float maxDistance = 5f;
private Vector3 currentVelocity = Vector3.zero;
private float currentYaw = 0f;
private float currentPitch = 0f;
public float minPitch = -30f;
public float maxPitch = 60f;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void LateUpdate()
{
if (!target) return;
float mouseX = Input.GetAxis("Mouse X");
float mouseY = Input.GetAxis("Mouse Y");
currentYaw += mouseX;
currentPitch -= mouseY;
currentPitch = Mathf.Clamp(currentPitch, minPitch, maxPitch);
Quaternion rotation = Quaternion.Euler(currentPitch, currentYaw, 0);
Vector3 desiredPosition = target.position + rotation * offset;
Vector3 direction = desiredPosition - target.position;
RaycastHit hit;
if (Physics.Raycast(target.position, direction.normalized, out hit, direction.magnitude))
{
float hitDistance = Mathf.Clamp(hit.distance - collisionRadius, minDistance, maxDistance);
desiredPosition = target.position + direction.normalized * hitDistance;
}
else
{
float distance = Vector3.Distance(target.position, desiredPosition);
float clampedDistance = Mathf.Clamp(distance, minDistance, maxDistance);
desiredPosition = target.position + direction.normalized * clampedDistance;
}
transform.position = Vector3.SmoothDamp(transform.position, desiredPosition, ref currentVelocity, smoothTime);
transform.LookAt(target.position + Vector3.up * 1.5f);
}
}
What am I doing to prevent it from detecting collisions properly?
!code
📃 Large Code Blocks
Use links to services like:
https://pastes.dev/
https://paste.yunohost.org/
https://share.sidia.net/
https://paste.ofcode.org/
https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
show only the part that detects the collision
I'm getting the typical error where it goes through the wall and there's no collision.
Then the code is wrong.
you still can, you just have to do it differently
for example by checking overlap
if you're making a "camera collision" you don't need to do any of this
Cinemachine already comes with a built in system for obstacle avoidance
The collision damages the player, but not the buildings and city.
how do you check if you collide with a building?
Is Cinemachine just a matter of installing it? I didn't want to use that kind of thing.
When I activate that script, the camera starts vibrating and can't be rotated.
im confused what are you asking here what does damages have to do with camera
probably script is wrong / fighting controls over its rotations with something else
So the camera respects the character's collision, but not the buildings'. I'll check if it's the building collision and let you know.
I need help with this really transform.forward = ledgeRay.normal;
Is there a way to make the player's rotation face a mesh at all times?
Like climbing in the ledged of zelda: botw
or rather more like uncharted
lookdir = (target - origin).normalized
quaternion.lookrotation (lookdir)
Thanks! Now the player is facing the ledge perfectly and I am moving on to implementing the actual movement along the ledge.
/// Move the player along the X axis of the normal of the ledge game object.
/// The speed is less than walking speed while hanging and climbing
/// </summary>
public void MoveOnLedge()
{
//Buttons
bool leftButton = UnityEngine.Input.GetKeyDown("a");
bool rightButton = UnityEngine.Input.GetKeyDown("d");
bool upButton = UnityEngine.Input.GetKeyDown("w");
bool downButton = UnityEngine.Input.GetKeyDown("s");
bool jumpButton = UnityEngine.Input.GetKeyDown("w");
if (leftButton)
{
//Move Player to the left along ledgeRay.hit.normal X-
}
if (rightButton)
{
//Move Player to the right along ledgeRay.hit.normal X+
}
if (downButton)
{
//Turn player in opposite direction Y-
}
if (upButton)
{
//Move Player to the top of the ledge Y+
}
}
not the best way of moving your player
could be 2 lines of code instead
Really?
yes really
Okay, total newbie question (I am a total newbie, I have no experience in coding), but what would be the code that I use here for applying player movement? I've looked at the documentation for the new Input System, and I got this far, but I just can't find the code for applying the movement with the moveValue.
if you want to move physics based you could use the rb velocity or addforce
these 2 methods are always recommended
yo i need help with making a 5 player online game for my comp science lesson i can make sprites and all that but im too dumb and lazy to code, if somone has like some basic project that i can steal it would be awesome
i can make soundtracks too i guess
@honest marten youre doing cs but refuse to code?
apply the values returned
if you're using a character controller look at examples like
https://docs.unity3d.com/ScriptReference/CharacterController.Move.html
i can help but only in the context of helping you learn
i mean i did make a platform game back in the day but multiplayer is another level man
on game maker..
to be honest its not that bad, i assume youre learning about async?
asynchronous programming?
this isn't the server for asking projects / do homework for you.. this is to help if you're stuck on a problem
nah man im in highschool i just expand cs and math
understood. well as i said i am happy to help but i wont write code for you
dw
you should learn and understand unity a bit first though no?
is it possible to learn it in 7 days
if you have an experienced background in something sure
i would say going from no knowledge of game dev or programming would make both harder to learn conceptually
why are you even taking computer science if none of this stuff intrests you to learn or actually do work
i mean im in high school man
this isn't even college?
well, i would argue you should take it seriously anyway, if nothing else youll gain a new way of thinknig about problems
why bother making a multiplayer then lol that seems overkill for some hs project
think thats his assignment @rich adder
idk the teach said that its a requirement
they would assign it if they taught it, they probably did no learning now wants to rush through
quicker
i can use anything
i could even make a game in roblox but i dont think im that lazy
find some code for geometric shapes, make it squares and lines, make it a 4 player pong game, use libraries, done
all of that should be achievable i think
but again, you gotta like...at lesat have an idea of what youre doing
what about something like claude code
maybe, i dont know. you gotta make the call
i used it once but it didnt make sense to me
anyway this isn't the place for that
yeah and they most likely gave you a few months to do it
actually he said that i need to make a game til the end of june like 4 days ago
i mean may
but im not really a coder man
im a composer
Sorry, I'm really new to this. I'm not quite understanding what you mean by "apply the values returned". How would i do that, if you are able and willing to answer? the example script is so much different and more complicated than what i have, and I'm not at the skill level in coding to problem solve that yet. Sorry for the probably dumb questions
it appears more complicated then it is because theres a lot of lines.
if you isolate the relevant parts to input and movement.
Vector2 input = moveAction.action.ReadValue<Vector2>();
Vector3 move = new Vector3(input.x, 0, input.y); // its applying vertical input (y) to the Z so it can move forward/back in 3d space, the x is side movement. in 3D
// Move
Vector3 finalMove = move * playerSpeed + Vector3.up * playerVelocity.y;
controller.Move(finalMove * Time.deltaTime);```
Thank you so much! A appreciate you, and I will be doing my best to research and understand all this!
sure.
btw the inputs will return to you values -1 to 1 on each axis
im back
You don't have to announce it lol
i couldent figure out why hes weird
its clear once you post an actual question
announcments are a big part of the amarican culture
like santa
screaming when he comes into your house
hilarious.
go make a tweet then, on this server you don't need to spam
oh
if you need help with art assets go to #🔀┃art-asset-workflow or #🖼️┃2d-tools
this is a coding channel
Hey I implemented a MoveOnLedge function and my player moves along the ledge now! Here is what I have if anyone has an idea on how to turn the character when they reach a corner
public Vector3 MoveDirection()
{
return Vector3.zero;
}
/// <summary>
/// Move the player along the X axis of the normal of the ledge game object.
/// The speed is less than walking speed while hanging and climbing
/// </summary>
public void MoveOnLedge()
{
float horizontalInput = Input.GetAxisRaw("Horizontal");
float verticalInput = Input.GetAxisRaw("Vertical");
// calculate movement direction
moveDirection = orientation.right * horizontalInput;
rb.AddForce(moveDirection * 0.1f, ForceMode.Force);
if (Mathf.Abs(moveDirection.y) == 0f)
{
moveDirection.y = verticalInput;
}
else
{
moveDirection.y = verticalInput;
}
if ((Mathf.Abs(horizontalInput) == 0f))
{
rb.linearVelocity = Vector3.zero;
}
}
bro what the fuck are you watching in the background
Sorry was a podcast
jfc good thing my audio was muted
i just blasted that full volume on my speakers 😔
I can make one with no audio
no its fine lol it just caught me off guard
but I would like to share this code with others when im done
im trying to make an easy way to ledge climb
could probably do it in #1179447338188673034 when done
maybe updates in #1180170818983051344
is there a way I can get the frequency and damping behavior from a SpringJonit2D on a SliderJoint2D?
Or conversely can I get the behaviour provided by the angle parameter from a SliderJoint2d for a SpringJoint2d?
nvm idk why i thought i couldn't use both components on the same gameobject that had bad results
guys where can I find a tutorial or guidebook for all of the common physics and rigidbody scripts? I made a few scripts using AI, but, I wanna fix some details on them and, since Gemini cant code them correctly, I'll have to learn how to code them myself.
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
the docs got all you need for info on specific components https://docs.unity3d.com/6000.0/Documentation/ScriptReference/index.html
thanks
Heyoo, I was wondering what the best way is to determine if an object is being occluded by a wall? Raycasting to AABB corners works fine for something like boxes, but when trying to determine if a sphere is being occluded, raycasting to the AABB corners doesn't work well. I tried using sphere casting but that can lead to false positives as it can get caught on the edges of the wall. Is there another way that is most accurate that I could go for?
Could you explain the context around this issue? What you need the occlusion information for? One common solution is to fire a larger number of rays in some kind of grid pattern. There is no fast and perfectly reliable (never false positives or negatives) occlusion algorithm. Well technically you could render the image to an object ID buffer and calculate the occlusion from there in a compute shader for example but the problem with that is that even though it could probably be implemented pretty fast, there is no fast readback from the GPU so there will be couple frames of delay to get the information back to C# side
basically I just want to check if the object can be seen by a player
Hmm yeah I may need to find a better solution then. The goal is to have like ten of these enemies moving around, so I fear that may get expensive and slow very quick.
sorry i just realized this doesn't really clarify much beyond my original statement lol. If a player is looking at an enemy, then the enemy freezes and is unable of moving like SCP 173.
Do you really need near perfect detection though? Is one ray at the center not enough?
You can make some points manually to raycast to
Well, I want to eliminate the possibility of a player being able to see the enemy move as that'd ruin immersion. It's a horror game so preferably I would want to reduce the chances of them seeing the enemy move.
However I suppose I could do some prediction and flicker the lights or something like that if not possible. That would theoretically prevent the player from seeing the movement 🤔
im confused, is the player ever supposed to see the enemy then?
i feel like this is an xy problem more than anything
I think the point is the player is never meant to see the enemy move
Sorry I may be a bit unclear. They are supposed to watch the enemy because they don't want the enemy to get closer to kill them, so ideally you want to be looking at them. What my problem is, I want it to be accurate because I don't want them to be able to see the enemy moving.
i feel like theres a simpler way to accomplish that
then dealing with perfect ray detection no?
I see. In fact you might be overthinking the performance impact of raycasts. If you don't have much else going on, it might be totally feasible to make many raycasts. And you can combine it with frustum culling to improve efficiency
Yeah raycasts are as cheap as they come
well, I want the enemy to be able to move when the player is not looking at them, which would include being behind a wall. Though they'd be visible if parts of their body were visible around the edges of the wall. I'm not sure how else I would be able to accomplish that without perfect ray detection
couldnt you just use something like "Renderer.isVisible"
basically the enemy listens to the player, to see if it can move at all
yeah but in a combination with a raycast you dont need much more no?
hmm I'll need to test that
i might be overthinking it, and it could be overkill, but if you want to ensure that even if a smidge of the enemy is peaking around the corner, you could get the enemy's 3d boundaries as 2d screen coords and then basically hit it with a lidar scan of raycasts lol
You can also provide simpler colliders, like boxes for your enemies to do less raycasts. It might stop moving a little earlier, but small margin shouldn't be a problem, right?
I think that would be very reasonable approach. One probelm that I'm wondering just now is that if you have shadows enabled, you might see that shadow moving even though the object itself is not in view, would that be an issue? isVisible I think returns true also when it is visible to some of the shadowmaps but if you need to take that into account in your raycasting logic, it would quickly get really complicated
Oh yes, the shadow will be a problem. I need to account for silhouettes as well
the shadow thing doesnt seem so bad
honestly from a design perspective more than anything
could be a cool problem turned feature
The enemies don't walk. They just teleport so it would look kinda funky haha, but maybe it'll look cool. I did it this way as it is a multiplayer game, and it would be possible I believe, due to latency, that you could see the enemy moving if it was with just default walking.
oh i got some bad news
if its a multiplayer game, theres almost 0% chance you can guarantee the enemy wont ever be seen moving
unless its movement is entirely client side
I mean you would get closer by increasing the margins (like the size of their colliders) enough
Multiplayer kinda makes it 10x more difficult, as you'll either need to simulate every player camera on the server, or deal with latency uncertainty.
latency is gonna be the biggest issue
yeah you're right aghh
i cant think of a single multiplayer game with this kind of mechanic thats done it proper justice lol
even scp secret lab try as they might cant get scp 173 to look good
its just a flying peanut half the time lol
then no matter what I'll have to probably make it so, if a enemy is somehow moving into a player's perspective and is not frozen, perhaps I'll just flicker the lights on the client for however long the duration must be
ive been working on this game for 5 years haha. The first 4 were on Roblox. I am dedicated to making this mechanic almost perfect
I made an attempt at trying to get the player to rotate using a spherecast but it doesn't seem to work?
Code:
private void CheckCorners()
{
///////Rotate around corners BELOW///////
//Create a forward Raycast
if (isHanging)
{
Debug.DrawRay(LeftChecker.position, move.orientation.forward * 1f, Color.red);
Debug.DrawRay(RightChecker.position, move.orientation.forward * 1f, Color.red);
if (!Physics.Raycast(RightChecker.position, move.orientation.forward, out RaycastHit lineHit, 1f))
{
if (Physics.SphereCast(RightCornerCheck.position, .1f, move.orientation.forward, out RaycastHit sphereHit, 1.5f, whatIsLedge))
{
Vector3.Slerp(transform.forward, sphereHit.point, 1f);
}
}
}
}
I have a raycast that checks for when there is no ledge on the side. I then create a sphereCast that is supposed to hit the side of the wall around the corner. When it hits the player is supposed to rotate around to the hit point but it isn't functioning properly like how I intended. I might have to create a ray from the side of the wall in stead of a sphere.
You're not using the slerp result in any way.
And the params are all over the place as well. A is a direction, b is a position. T is 1, so the result would always be the sphere hit point(position).
P. S. You should use debug rays and other gizmos more actively for visual validation. Make sure to use different colors too to make it clear what's what.
Okay i have a design question in my first ever Unity game. My game has multiple rounds. In each round, the player drops all of the balls they have down a pegboard. In between rounds they can add balls to their collection.
My question is, how do i store all of these balls in a list that persists between rounds. I’m confused because the actual game objects won’t persist, but i still need to know what balls are in the users collection
Btw these different balls behave differently, it’s not just a different sprite
In this tutorial, you’ll learn how to use data persistence to preserve information across different scenes by taking a color that the user selects in the Menu scene and applying it to the transporter units in the Main scene. By the end of this tutorial, you will be able to:
Ensure data is preserved throughout an application session by using t...
I guess I’m more asking how to store the balls
Instead of a list of game objects
A list of what
can't you just write in files? or store the data in a singleton?
huh?
whatever type your balls are? if they have specific component use that
List is generic you can put whatever you want as long as the type is the same
Anyone learned the HSM? (hierarchial state machine)? if you did, what resource you checked to learn it cuz rn im confused
But can i have instances of the type my balls are, without having game objects to go with them
you mean physically ? cause in most cases you just store the data so destroying (via scene change) for example would have no impact
Let me reword bc i think I’m confusing myself and you guys on what I’m asking
During the round the user will have a bunch of balls to drop, which are game objects that are destroyed when they reach the bottom. But even when the game object is destroyed i still need a list keeping track of all the balls they have currently bc they drop them again next round
I was under the impression that one instance of my hall class is made per game object
yes which is why I said normally you store the Data itself not the instances of gameobjects
Okay so i need to store data that describes the ball
yup
And the prefab would be included in that data?
Like let’s say I have prefabs for different kinds of balls
POCO works too
If they have completely different prefabs then you could store the preab too ig
What’s SO and POCO
ScriptableObject
and Plain Old Class / Clr object
Ah okay
Well i can make a scriptable object i was planning to do that after your recommendation
But the SO needs to store the prefab right?
using POCO rn and it's annoying cause i always get "MissingReferenceException" whenever i stop runtime
strange.. depends how you're using it though
you can store it in a plain class as well , what makes easier in SOs is they are templates you can create instances of In inspector
well the plain class has reference to a few monobehaviours when runtime stops they cry cause they are now missing and GC hasn't cleaned the plain classes yet
(ps sorry for popping in the middle of a conversation)
Okay you may have technically answered this in something you said, but I’m a bit lost on one thing. Let’s say i have a scriptable object, which has data to represent a type of ball. If I’m not storing a prefab, how can i actually make a game object from that SO
strange but not sure cause I don't remember if I haver used any MBs in POCOs
what exactly do they have in common, most of those go in Prefab
what kinda data do they hold
Wait what kind of data does what hold
balls ?