#π»βcode-beginner
1 messages Β· Page 597 of 1
internally is just doing a raycast... the interface methods are what make it more particular
You do need the physics raycaster. very important.
so you put that on your camera
yes
i also have a graphics raycaster
b/c im never sure which one i need π€£
i just add both
the 2d one
Physics = colliders
Graphic = canvas
okay that makes sense
yes you need the 2D one for 2D colliders
then ur IPointer stuff just works out the box
and then i can implement IBeginDragHandler, IEndDragHandler?
indeed
uh its now just stuck to my mouse
Try this alternatively:
{
private bool _dragging;
private static Camera _mainCamera;
private void Awake()
{
_mainCamera = Camera.main;
_dragging = true;
}
private void Update()
{
Debug.Log(_dragging);
if (!_dragging) return;
var mousePosition = _mainCamera.ScreenToWorldPoint(Input.mousePosition);
transform.position = new Vector3(mousePosition.x, mousePosition.y, 0);
}
private void OnMouseDown()
{
_dragging = true;
}
private void OnMouseUp()
{
_dragging = false;
}
}```
With this:
```public void AddObject(GameObject instance, bool isBackground)
{
gameManager.IncreaseObjectLayer();
var mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (mousePosition == null) return;
instance.transform.position = new Vector3(mousePosition.Value.x, mousePosition.Value.y, 0);
}```
But idk Pointers are probably better
Sorry i meant Ipointers
when i do Ipointers i dont use teh drag
i do ti manually..
i use the Down,, Enter, Exit, etc
just like the OnMouse ones.. but Interfaces instead
Drag is doing the drag threshold for you and some other bits such as tracking the "dragged" object and allowing use of the drop event
u know u can expand ur EventSystem too btw..
did you use the 2D physics raycaster on the camera
it shows important debug stuff too..
yes
theres some good reference on the docs on IPoiunters: https://docs.unity3d.com/6000.0/Documentation/ScriptReference/UIElements.PointerDownEvent.html
it doesnt have an arrow
or XD do you mean adding extra events
i have this and the collider but
it'll have a box below it once it goes into play mode
this one is even better
https://docs.unity3d.com/Packages/com.unity.ugui@3.0/manual/SupportedEvents.html
ah
its all the info about what the event system is seeing.. doing.. etc
well
This is broken and gives like 0 info with the new input system π¦
aww π really?
you only get clicked events now when selected
THANKS UNITY
i didnt know it was broken now..
.-.
new Input module is a disgrace
lets wait for input system no 3
ye my teach er wanted us to use the old one
(β―Β°β‘Β°)β―οΈ΅ β»ββ»
thats good imo. i still rock the old one..
until i cant anymore lmao
someone at unity : lets give them even less info
you get a raise!
brilliant
ok so any ideas why my drag events dont fire
remember you need the correct raycaster for 3d/2d physics. Also CHECK THE LAYERS
keep in mind the iPointer methods goes on the object with collider iirc
show the full script
use links
links?
eyy you need the physics 2d raycaster
ye thats on the camera
also add a sprite cus the sorting is fucked without one
!code
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π 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.
the sprite sorting layer will affect the raycast "layering" so make sure its above other colliders in the scene
its the only thing in the scene where im clicking
im clicking on this part
nothing is in front of it
or behind it
you couldDebug the EventSystem raycast and see if something is blocking the ray
hide your UI to be sure. Also try adding a rigidbody 2d too
na raycasts dont need rigidbody just colliders
ill check a project that uses 2d physics with the event system a lot i forget...
didnt fix it
wait do i need anything on my EventSystem object?
input module and event system
ok i have those
check this to
this is why i quit my UI/UX job π
when in doubt Debug it
[SerializeField] EventSystem eventSystem;
[SerializeField] Physics2DRaycaster physics2DRaycaster;
void Update()
{
PointerEventData pointerEventData = new PointerEventData(eventSystem);
pointerEventData.position = Input.mousePosition;
List<RaycastResult> results = new List<RaycastResult>();
physics2DRaycaster.Raycast(pointerEventData, results);
foreach (RaycastResult result in results)
{
Debug.Log("UI Hit: " + result.gameObject.name);
}
}```
no idea then, I know this should work though so something must either be in the way or the script is in the wrong place
create new scene -> make bare-bones ass example
get it working in that scene.. then u have a nice comparison
but thats double the work
not really.. if its Investment into getting ur OG working..
and i doubt i can get it to work in there but ill try
it'd def make things simpler.. just use 1 image. 1 canvas 1 of everything
no clutter lol
try printing whats hitting
#π»βcode-beginner message
yall got this π coffee break β
any script, can even be a new one
just reference correct components by drag n drop
plop event system and 2d raycaster in there
ok not apparnelty
a prefab doesnt work
π
well no.. put it on something in the scene why did you put it on a prefab
prefab should not reference scene components
because i want it in every instance
i hate that you cant do that
why would you want many instances of a raycast for testing
i dont in this case
you only need 1 script to test the raycaster on
there you go
whoa where do u see that??
armchair is hitting
wtf ui is that
ohh thats awesome that u get those logs in rider
i lack space in unity
well UI is misleading comment but yes its hitting whatever that collider is
so then why is the event not firing
ye
i can also have it like this
thats what debugging is for. At least now you know the Physics raycaster is working
Can I not see the data stored in a Dictionary from the editor? Do I have to like convert it into 2 List or something?
it is, otherwise you wont see these events
yes dictionary cannot be serialized
oh
nested struct
Nope. You need to use a custom property drawer or the many serializeable dictionaries online . . .
π₯
let me test
ok that seems to be fixed
but now i cant drag it out of the UI again
its behind it tho
how do i fix that?
is it with sorting layers?
the 2d physics stuff cannot be "over" the UI unless you use a canvas in world
you should be able to use Screen Space camera then drag camera inside and figure out the correct number
oh i cant?
it can
so sorting layers or how do i do it
the plane distance
like the z transform?
it shouldn't be possible with overlay canvases but the other modes i presume can
the whole point of ScreenSpace - Camera is it takes into account world pos
well yea that is what i thought
tbh I have tested it with renderers and sorting Meshes infront of UI elements, but idk if it works with colliders
go into Canvas, set it to ScreenSpace -Camera
sprite renderer is just mesh
ah it was on overlay
well it renders it correctly so thats somethiing
ye that works
nicee
so how do i set you dragging an object
like i create the prefab
but then i need to set the player grabbing it
Instantiate returns copy of the object
so they dont have to click twice
so you can do like
var myDraggable = Instantiate(etc. myDraggable.followMouse = true
Bro i found the reason why the old OnMouseUp wasnt working:
you have to add this to the start of update:
if (Input.GetMouseButtonUp(0)) { OnMouseUp();}
I tried it myself and everything works perfectly but without the events:
if u want i can send u the old scripts again @fleet venture
how is it following mouse?
i just have this now
public void OnDrag(PointerEventData eventData)
{
var mousePosition = _mainCamera.ScreenToWorldPoint(Input.mousePosition);
transform.position = new Vector3(mousePosition.x, mousePosition.y, 0);
}```
sorry for the syntax
ther
but now i am doing it thru events
I would switch it back to a bool
you sure?
100%
this sounds like it was more meant to be used
Moving in Update following is very common
especially if you dont want this double click weirdness
doesnt work with public void OnEndDrag(PointerEventData eventData)
{
_dragging = false;
Debug.Log("OnEndDrag");
}
no
OnPointerDown => mouseFollow = true
OnPointerUp => mouseFollow = false
Update
if(mouseFollow)
myObj.position = mousePos```
or do i use the Ipointer now
this way you can set mouseFollow from another script too
this is the original that didnt work
if OnDrag works , it will work, just make it more simple with less bools than whatever you did before
if i add this tho it does
no but this ondrag is with events
so do i use IPointer?
this is literally a general mouseDown event, it doesnt care if its on the collider or not
also wrong
no this was the original code it did not work
You should never be calling Monobehavior methods manually
OnMouseUp would be properly called when it releases from a collider
what is wrong
no its only called if you also have a mouse down for some reason
this is my original code
that did not work
forget the original code
but your code is the same
no its not
are we getting anywhere guys?
yes we're in step 2
noice
i bet this wont work
scrapp OnDrag for Uppate mouse follow so bool can be set on spawn, this way object spawns following mouse
I bet it does
yep doesnt work
i bet on nav
mate before you yap away it doesnt work
untill i click again
show what you wrote
ok
just like me telling you Screenspace -Camera wouldnt solve UI blocking colliders ?
no that works
so then be patient and actually listen to the instructions correct , it will work
done this 100s of times..
ok so put logs inside the methods make sure those are being detected
is it on the same object with OnDrag was ?
they are because if i then click it releases
this works just not when dragging from ui
wdym by this
Just add if (Input.GetMouseButtonUp(0)) { _dragging = false;} at the start of your Update and it will release
ye this will fix it
but nav said its bad
ok then
No i said Manually calling OnMouseDown is bad
explain whats happening
i agree that was stupid
is it just not releasing ? then yes you just need to set bool back to false obv..
if im understanding u click an original object and then u spawn in a NEWER object..
ah okay
that was never had ondown or w/e called
yup
so onup doesnt get called until u click down again
u might need to call ondown maually
on ur new object
ye
UI icon spawns the prefab thats supposed to follow
thats what happens
so that onup will be called
ye but i thought calling the events yourself is bad
PointerEventData eventData = new PointerEventData(EventSystem.current);
eventData.position = Input.mousePosition;
newSpriteGameObject.GetComponent<YourDragHandler>().OnPointerDown(eventData);```
you dont need those though cause you're already holding
something like this to manually call the OnPointerDown or w/e
should i just try this?
ya but i think he uses hte Orignal icon as a button and spawns in a new object (the new object was never OnDowned on.. the original was)
you grabbed the item your mouse should already be down..
all you need is the MouseUp event from the Input itself
yep
thats whats happenign
new object has a bool set through a method on instantiate
ye but that MouseUp event isnt getting called
thats why we switched away from OnDrag
i checked that with debug.log
oh i didnt see that
why not its one line if it works it works if it doesnt it doesnt
what MouseUpp ?
OnPointerUP i mean
You dont need OnPointerUp..
i remember doing something like this.. where another script takes over.. i had to pass the new object into the EventSystem
you literally told me to use it here i thought
yes and you said it working no?
great
hows it not working
it doesnt call the up event
so it is working as In its following
bro ur confusing everything
just because one part doesnt work doesnt mean the whole thing aint working
https://paste.ofcode.org/385muzFnP2cceDebSzx9L2E this code just works
just say, Yes its working EXCEPT its not releasing
are autoproperties like this
[field: SerializeField]
public int Age { get; set; }
the best approach for fields that could need custom get; set implementation?
this way we know yes all you needed was flag to false
stop saying "it doesnt work"
this code does EVERYTHING
"it doesnt work" implies the whole thing is not working
SO IT WWAS WORKING IT WAS JUST NOT RELEASING
well the dragging part has been working from the start
jesus christ
ok but ive been saying that the whole time
you just sauy "doesnt work"
like here
dont get mad at me
ok
man if it works that fine so its done here right?
im just telling you to be more specific next time
we can all be happy now
// used via button events
public void UnfocusEventSystem()
{
SettingsMenuEventSystem.SetSelectedGameObject(null);
}``` i was way off track.. i was thinking the event system was losing the reference.. or referencing the *last* object.. not the newer draggable one..
was gonna suggest feeding the new object into the event system as Last Selected
just one thing
but u kno.. im not the brightest crayon in the box
i got it now π
is there a way to get the pixels inside of the object where you clicked
Phew..
like if i click entirely left of the boject i get 0
and if i click entirely right i get like 100
ye Because rn it always centers the object when you click on it
but i only need to move it by the delta
so i need that offset
So in unity I am making a fps horror game. You can look around with the mouse and to move instead of moving by using your keyboard you move by clicking where you want to go so click to move. I have a issue where when I either repeatedly click at the max click distance or just click a bit close to me instead of the player going to the place where I last clicked the player will just keep moving until I stop clicking which I don't want.
Script (Sorry is the coding is garbage XD) : https://paste.ofcode.org/FP6zGBS2sFdPBnhqyLZrvX
Watch "My project - SampleScene - Windows, Mac, Linux - Unity 2022.3.26f1 DX11 2025-02-07 16-44-51" on Streamable.
you can get the offset from click pos to object pos and keep that offset when moving it
ye but how do i get the offset?
ye but how do i get the clickpos, thats what im asking
you literally have it already
ScreenToWorldPoint
when ur First click... cache that clicked position..
instead of constantly updating it..
when u release u'll be able to cache the next clicked position
ok got it working ty
Good evening. Who has a normal code for moving the character right-left with a jump. I just can't get a normal result. The maximum that I could get is that the character jumps only on certain platforms and that's all
in a 2D platform
There is no such thing as "a normal code". Every game is different.
If you are having trouble with your code feel free to share the details of your problem and people may be able to help you.
My problem is that the character jumps only on 3 blocks. The rest of them don't.
show code
whats "ODA platforms "
Guys, I dont know what is wrong with this code, But i'm pretty sure i've written this right, for it to dash, or ATLEAST move. It just modifies the X velocity of the Rigidbody, and It even modifies (or so it shows in the console) but the velocity doesnt change in the Inspector. It registers the input, but doesnt perform the dash. Pls Help TwT
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hero : MonoBehaviour
{
[SerializeField] private float speed = 3f; // ΡΠΊΠΎΡΠΎΡΡΡ Π΄Π²ΠΈΠΆΠ΅Π½ΠΈΡ
[SerializeField] private int lives = 5; // ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΠΆΠΈΠ·Π½Π΅ΠΉ
[SerializeField] private float jumpForce = 15f; // ΡΠΈΠ»Π° ΠΏΡΡΠΆΠΊΠ°
[SerializeField] private LayerMask groundLayer; // ΡΠ»ΠΎΠΉ Π·Π΅ΠΌΠ»ΠΈ
private bool isGrounded = false;
private bool canDoubleJump = false;
private Rigidbody2D rb;
private SpriteRenderer sprite;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
sprite = GetComponentInChildren<SpriteRenderer>();
}
private void FixedUpdate()
{
CheckGround();
}
private void Update()
{
if (Input.GetButton("Horizontal"))
Run();
if (Input.GetButtonDown("Jump"))
Jump();
}
private void Run()
{
float moveInput = Input.GetAxis("Horizontal");
Vector3 dir = transform.right * moveInput;
transform.position = Vector3.MoveTowards(transform.position, transform.position + dir, speed * Time.deltaTime);
if (moveInput != 0)
sprite.flipX = moveInput < 0.0f;
}
private void Jump()
{
if (isGrounded)
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
canDoubleJump = true;
}
else if (canDoubleJump)
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
canDoubleJump = false;
}
}
private void CheckGround()
{
Collider2D collider = Physics2D.OverlapCircle(transform.position, 0.3f, groundLayer);
if (collider != null)
{
isGrounded = true;
canDoubleJump = false;
}
else
{
isGrounded = false;
}
}
}
maybe try rb.AddForce with ForceMode.Impulse https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Rigidbody.AddForce.html @grizzled current
It Still didnt work bro π₯²
Post !code using a paste site so it doesn't take up the chat and hide other people's questions and answers . . .
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π 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.
hard to say without seeing your other code but most likely your other code is simply overwriting the velocity rendering your dash code useless
do you have some crazy friction on Physics Materials maybe?
Yea, true. I'll take another look and report
No π₯²
Pretty sure you would rather use AddForce in impulse mode
Just straigh up setting velocity makes it interact very poorly with the rest of physics
the problem is the main movement code is setting the velocity probably - but he didn't show it
then its probably some other script yeah
I feel so stupid. You guys were right, The main "movement" func was called on every frame, which resets the velocity to zero. Thanks a lot tho, I feel relieved lol
use debug logs more often then u even think u should
Yea, I really should. Thnx a lot, everyone
you are mixing transform position setting with rigidbody movement, this is bad
also yes post code properly #π»βcode-beginner message
How do I put a method and/or a list of methods in the inspector just like this?
You mean like a list of delegates? idk wat you mean put methods in inspector
what do you want to do exactly? whats the end goal here
i have some methods for movement, like dash, jump, etc, and I wanted to change the Input Sequence from Attack Data to a list of methods that needs to be done to the attack to be triggered
I would use scriptable object
Create an SO with the method and its parameters as fields. Make a list of SOs and drag them in . . .
that's what I'm doing with the Attack Data, and I want to add the method list into it
The SO is just a wrapper for your method(s) . . .
no like each time you do an action you compare it with that scriptable object to one in list of attack data
theres 2 how do i fix it
so you have your DeshSO that you use when you dash
and compare it if its part of the attack data list of SOs
from this video alone we are supposed to guess? not happening
wydm
what is this video supposed to tell us ?
there is two, great.
how's that help anyone help you ?
#854851968446365696
read also the Asking Questions
this is pretty bad transform.position = Vector3.MoveTowards(transform.position, transform.position + dir, speed * Time.deltaTime);
you should not be moving like this with a rigidbody
so I get a SO containing the methods to dash and stuff, and then I compare if these methods are being called in another script so I can land the attack?
Can you create a good cood or fix Bad pretty
you gotta fix it, its pretty simple at least for that line. you already have the rigidbody referenced with rb. use the same thing you did for jump but x axis instead
Ok. Thax
like if you have a SO for Dash, its the same one from the List in Attack Data, but you are creating/using the one referenced on Dash move and putting it in another list to compare the list on Attack Data
there only meant to be 1 not 2
yes we understand that
so how do i fix it
use common sense for a second..
oh so in Attack Data, I make a list of SOs instead of a list of methods directly, right?
do i need to change anything
do you think this video tells use WHY its happening ?
i just send a photo
this isn't enough
i never done a camera stack
anyway just separate the layers and use culling
how
aren't you following a tutorial or something?
what tutorial
so you're just guessing your way ?
yup exactly
make the list match the sequence you want
if both lists match then you're good, or you can check when it goes wrong while adding elements to list, then do whatever depending on behavior you want
ok then, thx
Camera1. Remove WeaponLayer from it
Camera2. Remove all layers except WeaponLayer
im trying to insantiate a UI text that says "achievement unlocked" when i reach a certain score, my problem is that when i instantiate the gameObject it doesnt show in my UI
i think its because im putting the postion in incorrectly, how do i make it show on the canvas and not the camera
My input action looks like this. How can I detect specifically left being pressed down? Something like ```cs
input.actions["Move"].["WASD"].["Left"].started += ctx =>
if(myInput.x < 0)
btw you should generate the c# class
using strings is ugly
I don't mind it
lol ok
how
go to the input action asset, in the inspector tick the Generate C# class checkbox
give it a name that isn't taken
then you can use actual type safety properties
Awake () myInputs = new()
OnEnable() myInputs.Enable()
OnDisable() myInputs.Disable()
myInputs.Player.Move etc..
and what is myInputs?
does anyone know how to instantiate a UI element onto the canvas and not the camera
the variable for the class you generate from the Input actions
eg
so private MyInputs myInputs
obv make a better name but dont take ones unity made already like PlayerInput
thats a garbage name for example
I had weird luck changing it
make the changes and hit apply and hopefully it works
otherwise try re-generate after you delete the old class
the class shouldn't be touched after, since each time an action map save is made it updates it
Hey dumb question but I have some low poly textures I wanna use but they all look blurry , anyway I can fix that ?
this is a code channel
nav its just settings like toggle fullscreen and quality
so just for the ingame?
yea
or permanent between sessions
PlayerPrefs should be acceptable
yea im trying to use them but idk how to for toggles
store them as int
I cant come up with another one lol
then use ternary
well action asset can contain multiple action maps
You can do MyPlayerInputs or something
idk
when its a private variable
yea ive done this bit
so whats problem ?
you can also group them together with a struct then json string it
that will take care of not having to do each setting seperate
public void SetFullscreen(bool isFullscreen)
{
Screen.fullScreen = isFullscreen;
PlayerPrefs.SetInt("fullscreen", isFullscreen ? 1 : 0);
PlayerPrefs.Save();
i have this
right now
how do i like
yeah so its not working or what?
make it save between sessiosn
this is probably also the worst thing to test in the editor btw lol
since you can't really fullscreen it
you have to test a build to see if its saving and loading the fullscreen thing correctly
otherwise you have to test something else that works in editor
quality setting might work I suppose
Hey
I want to create a free cam. The problem is that it Clamps the x rotation to 90 and - 90 and I dont know why, since it doesnt do this for the y rotation but its the same Code
this look cursed transform.localEulerAngles +=
well I first did it with tranform.rotate but that didnt work at all
You should manually touch the eulerAngles
Rotate wants specific amount to rotate by
you can aslo just transform.rotation = quaternion.euler
either way you should clamp sepearate floats then pass those
Yes, it's easiest to just store the yaw and pitch values in fields
and to then set the rotation based on those
I dont want to clamp them, they the x-axis is but I dont want that
oh so you don't want clamp
yes but it does it on the x-axis
then just rotate without clamp just dont manually touch the euler angles cause you're experiencing gimbal lock
the angles are really meant to stay between -180 / 180
the inspector is just...a special case..where its done internally
Hey guys this might be a bit iof a confusing question but Ill try to make it as clear as possible so I made a public bool called isclimbing in my player script and then inside the ladder script I refrenced the player and then accesed the bool by doing _player.isclimbing and then now I added a box collider to the ladder and added a script to it and trying to aceesss the bool I tried doing the same thing that I did in the ladder script but it didnt work so i assumed you can only refrecne from another script one in a prefap so Im trying to acess the isclimbing bool to the cube game object script that I added to the ladder prefap you guys know what I should do and if any clarification you guys ant let me know becuase I am going crazy on this I dont want the day to end without me finishing thisπ
First of all use punctuation, that's barely readable.
Secondly, to get the bool off an object, you need a reference to that object. If your box has a collider on it, you can have it do it's own OnCollisionEnter check for the player and react accordingly.
But really, your ladder should not be the one deciding on logic, it should be told what to do. The player should be the one determining if it's in range to use a ladder or not, and if the player interacts with it, then the player should tell the ladder it's being used (and thus, it can react accordingly).
So all the logic is inside player the only thing in the ladder happening is if the player press e the bool turns on and then the player handles everything . And then whe you said you need a reference is it possible to get a reference on the box collider again because for some reason it worked on the ladder script but in the box colider script it wouldnt work I assumed you can only reference from a script one time per game object in prefab but Im a beginner so I was just guessing
Oh mb no ping forgot
What's the purpose of the box collider?
And no, any number of objects can reference the same object
you dont need any logic to run from box collider / ladder.
So when the player climbes and the box collider come up from the ground and wait for the player to go down if the player goes down and hits it with their leg the box collider will make the player let go of the ladder and the box will hide again
just identify that you entered a Ladder trigger
If it dosnet make sense Ill try to reexplain
Its attached to the ladder so when the player starts the invicible box collider is hiding under the ground the player starts climbing it goes up a little bit waiting for the player to go down if the player goes down and hits it its make the player let go and the collider goes under the ground again
Its attached to the ladder prefab
so its just the bottom of ladder has a box collider but not on ladder?
yes
Yah thats something ill work on later
oh okay so whats not working? can you also show code
and I guess you can only go up and down, not side to side?
this is the ladder
delete this one, send it as link from site in β¬οΈ
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π 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.
how tf do you want me to do it using tranform.rotate I dont know all these Rotation kinds and how to use them. havent rlly used them. What do I have at the moment Quaternion right? and tranform.rotate uses Euler?
Nav excuse me I gotta do something now do you mind if I comeback in like an hour will you be here
just repost your issue and someone will be here if not me
by showing code + screenshots too b
Rotate uses euler yea but probably not what you want since that moves by specific amount and not at set angles
t.rotation = Quaternion.Euler still uses eulers but you can set specific angles to object
if you dont want that but just continuous rotation then use rotate
So, I turned one of my interfaces into a monobehaviour; and I need to go back and edit every single one of the many, MANY inherits to remove every variable that's being implicitly inherited. I'm just wondering, is there a quick and easy way of doing so? Sooooo many scripts π
dont recompile until u do a big chunk of them :P\
navigate thru them via the IDE
why from Interface to MB anyway
My question is: why the change from MonoBehaviour to Interface?
u can right-click and rename to mass-edit
not sure it'll work in ur case but helpful to kno
It shouldn't have been an interface in the first place, I was confused with when to use interfaces π
i have an object colliding with another object but when I try to detect their collision it doesn't, what could be the problem
oh okay, so whatever property they inherit from their parent if its not different remove it from child class?
This is me reaping what I've sown (not reading the documentation before going ah! that's it! this should be an interface!)
I have this code here which is meant to check if the door is closed or open. Issue is, the ClosedROT = -90, but angle difference is at 120, so it doesnt think the door is closed even though it is. ``` Quaternion closedRotation = Quaternion.Euler(0, ClosedROT, 0);
angleDifference = Quaternion.Angle(transform.rotation, closedRotation);
if (angleDifference <= 2f || angleDifference >= 358f)
{
if(open)
{
GetComponent<Rigidbody>().isKinematic = true;
ClosingSound.Play();
open = false;
}
}
else
{
if (!open && !Controller.GetComponent<DragDoor>().isDragging)
{
GetComponent<Rigidbody>().isKinematic = false;
OpeningSound.Play();
open = true;
}
}```
I think?
I need to go through every child class and remove the properties it inherited from their parent, which are duplicated now
guys do you maybe know why the guy is teleporting and running away from the ball i have ai navigation.
its like the animation keeps replaying and he runs away
yea
dont know if there is a bulk way to remove that from different files
from this image alone ?
The Three Commandments of OnCollision:
Thou Shalt have a Collider on each object
Thou Shalt untick isTrigger on them
Thou Shalt be moving via a Rigidbody on at least one of them
I've seen people make customized groupings like what we see here in Advanced Settings inside their scripts, organizing several variables and stuff. I want to know how do I do this, becuz I cant find it on internet
this is a piss poor way to keep track state of door
you should keep a universal truth / bool for the state of the door and not rely on magical numbers
Omg. Figured out a good way.
OnTrigger is similar:
The Three Commandments of OnTriggerEnter:
Thou Shalt have a Collider on each object
Thou Shalt tick isTrigger on atleast one of them
Thou Shalt be moving via a Rigidbody on at least one of them
lookup foldout
In case anyone else finds themselves in the same predicament as I:
If your interface is similar enough, Ctrl F ~> Replace (in entire solution) is a pretty decent quick fix. Just make sure you have a back up of your parent script because it's gonna delete it on your parent script too
Thanks bro, it actually worked
I mean when I turned off the animation it followed the ball perfectly but as soon as I put the animation back it bugs out
thank Digiholic.. they're his 3 Commandments.. posts them everywhere he goes π
this just locks the camera from rotating even when adding the current rotation on top
most likely the animator is overriding the transforms
two components fighting for control over transform
never a good mix
Ok
Okay
Thanks
send current code rq
dont use pastebin
!code
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π 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.
- Base Object (main movement (code or something on this object)
- Graphics (graphical object.. animations and stuff should target this object and animate locally)
that way u can move the base object w/o screwing up the animation on the graphics
and vice-versa
ohgod
why are you doing thistransform.rotation.x inside a euler
rotation returns a quaternion
quaternion values clamp at 1
don't use quaternion vals
then can you please tell me how i should do it
something like
currentYRotation += mouseX * rotationSpeed * Time.deltaTime;
transform.rotation = Quaternion.Euler(0, currentYRotation, 0);```
etc
void HandleRotation()
{
float turnInput = Input.GetAxisRaw("Horizontal");
float rotationAmount = turnInput * TurnSpeed * Time.fixedDeltaTime;
Quaternion turnRotation = Quaternion.Euler(0,rotationAmount,0);
transform.rotation = transform.rotation * turnRotation;
}```etc
rb.AddTorque(rotationThrust * Time.deltaTime,ForceMode2D.Force);
i tried making a character with the character controller component, i added gravity and the character does fall, but the collision doesnt touch the ground
* Time.deltaTime in AddForce/Torque ?
ya, its gross lol
thats normal..
it does
its the skin of the collider
ur just seeing the skin
ohhhh so thats what skin is
yeah i saw it, why is it so high by default?
yes you want to keep it fairly decent so you don't clip into stuff
i keep its defaults
it helps smooth out collision with different heights
im making a third person game, the map is in a building
.08 is a pretty fair value
so it doesnt matter i think
u can probably go to .25 if u want
the player is not gonna see the collider tho.
.025*
you can shift the mesh child however offset you want from the ground
plus use things like IK for feet to make illusion of touching ground completely
its that prototype code.. mb..
u could easily change it to fixed.. or just omit all together if it was in fixedUpdate like it should be
i dont have many rb's laying around lol i will fix that right now tho so more copypasta later on isnt so brackeys
i just know that addforce already accounts for Time.fixedDeltaTime no ?
or maybe I misread
it does.. if its in fixedupdate
ohh okay
even the deltaTime accounts for it
if its in the fixedupdate loop
some c# guru learned me that not too long ago
it got garbled up with my fuel code
do i need to reinstall cinemachine to every new project?
yes. unless u use a template that already includes it
fixed it
Hey guys! I'm new in game deving stuff so i need your help. I'm using unity and now im stuck. I have a code, that spawns prefab on "CounterTopPoint" . The code itself works but the visual seems to be offset and doesnt appear on the "CounterTopPoint". Can you please share how to fix that?
show the instantiation code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClearCounter : MonoBehaviour {
[SerializeField] private Transform tomatoPrefab;
[SerializeField] private Transform CounterTopPoint;
public void Interact() {
Debug.Log("Interact!");
Transform tomatoTransform = Instantiate(tomatoPrefab,CounterTopPoint);
}
}
make sure ur prefab doesn't have an offset from any of the child objects
if they have any
//send small code like this
//from now on
` not '
mb for the ping but i got it working. it turns out when i downloaded the animation from mixamo i didnt check the box 'in place' now it works
root motion probs
lol.. poor animator
π
but if its not in place its root motion.
the animator was in charge of moving the transform.. which some ppl like..
i doo not
the hierarchy looks like this after interacting counter and spawning tomato
Whats the best way to check if a objects rotation equals a float?
simple == would result in an approximation..
you mean if one of the properties = a float?
.x etc
Yes the .y
float valueToCompare = transform.rotation.eulerAngles.y;
or transform.localRotation.eulerAngles.y;
I was told before to not read euler angles.
then compare that
reading them is fine.. even manipulating them is fine too if u know what ur doing..
if ur intending on comparing to a float.. ur observing its EulerAngles anyway
okay thanks
I have a empty gameobject with a script on it that should be spawning objects all around my canvas, it does spawn copys as I see them in the heirarchy but I cant seem to ever see them in game, I've messed with layers, ordering of the heirarchy, and what object I attach my script too to no avail. Some of that might make no sense I'm sorry lol, I'm new and confused
select one and press F while hovering ur scene-view
you'll see where it is.
we need more info as well.. the prefab ur spawning what is it? UI component?
the code that spawns it.. what values are they using?
Is there a way to require a serialized/exposed field in the inspector to accept instances of scriptable objects that implement a certain interface?
do the values in the objects transform/rect transform match what u expect.. or logged..
u figure that out and let me know.. as ive been trying to figure out if i could drop in my IInteractable interfaces
ive had to expose a gameobject instead
Ive found them ouside the canvas earlier, but I've dialed them into be within the screen, still just no visibility
The UI component question confuses me, I dragged the image from my project files into my heirarchy.
And this is the code:
Thank you for ur help!
if its an image u need to set its position w/ its rectTransform
as the transforms are not the same.. as for example a 2d sprite.. (which basically operates within worldspace)
@rocky canyon Try `[SerializeReference] and vertx's SerializeReferenceDropdown. I can't remember if it works for interfaces or just derived classes . . .
RectTransform newUIElement = Instantiate(yourUIElementPrefab).GetComponent<RectTransform>();
newUIElement.anchoredPosition = newPosition;
i wonder what that would do @coral cape ^
Vector2 newPosition = new Vector2(
Random.Range(-canvasRectTransform.rect.width / 2, canvasRectTransform.rect.width / 2),
Random.Range(-canvasRectTransform.rect.height / 2, canvasRectTransform.rect.height / 2)
);``` would spawn them across the entire canvas if its scaling correctly
i didnt know this existed.. coolio ill give em both a shot
op[]\ OP{}| |
Sadly, this doesn't work for instances of scriptable objects. I have a similar one (https://github.com/mackysoft/Unity-SerializeReferenceExtensions), but it suffers from the same fate π¦
I'm afraid I'm confused lol, I really am trying, I just dont understand where I would put that in my code?
This is it when running, it shows 5 clones on the left side as it should spawn 5
I've been messing with what you sent and getting errors with "-canvasRectTransform", am I supposed to be "using" a lib at the start? I only have "using UnityEngine;" rn
what about POCO Interfaces?
MY float could be -90, so it would cause issues.
If you're trying to do UI your comment says SpriteRenderer which would not be a UI object, just fyi
Also any UI element would need to be Instantiated as a child of a Canvas to actually show up
canvasRectTransform.. is the Rect Transform of ur Canvas (the ones the orb clones should be on)
right now ur spawning them (outside) the canvas... which would be world space..
UI's use a different system
for example my little icon here is UI / under a canvas.. it has a Z position of 0
which is clearly different.. than what a 0 position (in the world is typically) which is center of the world
these are using rectTransformComponent.anchorPosition = as well.. and not transform.position =
firstly you'll want to instantiate them as children of a canvas (if they are UI components.. which ur Orb that u have selected in ur screenshot is) i think since its under the canvas
public class DONTCOPYME: MonoBehaviour
{
public GameObject uiPrefab; // Your ORB
public RectTransform canvasRectTransform; // The RectTransform of the Canvas
void Start()
{
// Instantiate the UI element as a child of the Canvas
GameObject SpawnedUIELEMENT = Instantiate(uiPrefab, canvasRectTransform);
Vector2 randomPosition = new Vector2(Random.Range(-400, 100), Random.Range(-400, 100));
SpawnedUIELEMENT.GetComponent<RectTransform>().anchoredPosition = randomPosition;
}
}```
also im a bit confused.. b/c it seems u got a little bity world down there in the corner. is this spawning stuff game-play? game-play should usually be done in world space.. if u r dealing w/ canvas it should be for display/ui stuff only
evil orb has me thinking a bit..
Hey, Im trying to use DOTween for the first time but it's not working...
I have a 2d square prefab with this
transform.DOMoveX(100, 1);
a log is being printed before so i know it's getting there but nothing happnes.. no error either
am i missing something? in the tutorials it doesnt seem like there is a step up and on their doc it seem ineed to do DOTween.Init(); but there is not .Init() in using DG.Tweening
π
Why isnt this working? Tolerance = 2 ``` Quaternion currentRotation = transform.rotation;
// Preserve the current X and Z rotation, but set Y to ClosedRot
Quaternion targetRotation = Quaternion.Euler(currentRotation.x, ClosedROT, currentRotation.z);
// Get the shortest difference between current and target rotation
float angleDifference = Quaternion.Angle(currentRotation, targetRotation);
// Check if within tolerance
if (angleDifference <= tolerance)```
That all makes sense, i think lol, I def have a lot to look into, and yeah the evil orb is gameplay, I was confused what I was even doing when I went to scene and saw everything crunched in the corner lol. Just confused between things that seem the same but are clearly different in reference, will put a photo on the screen in any way I can then get confused how to manipulate it when I probably didn't add it right.
So to see if I understand correctly, I should have interactable gameplay objects like enemies outside of my canvas? the canvas should be specifically for overlays like UI and displays
ya it can be overwhelming to beginners..
- screen space ( like where the cursor resides (mousePosition) is based on ur screensize and resolution )
- for example going from 0 - 100 could be the full screen (sometimes u dont know)
- UI RectTransform stuff ( usually operate like a normalized value.. .5 x .5 is dead center.. top left is 0,1 bottom right is 1,0 etc )
- this is true b/c of scaling b/c usually your canvas will scale.. some of the values above may be a bit wrong b/c i cant remember the order the screenspace goes in) the anchorPosition is based off of the element its a child of..
- Then world-space is split into local/global but its the game stuff.. (like where u create a cube.. its dead center of all the axis)
yes.. u can get a bit cheeky w/ animations and stuff but its even frowned upon to animate UI but rather use Tweening libraries.. b/c animating it means it has to redraw the entire canvas every frame)
if its ortho or something u can find a good bounds to follow.. w/ the camera gizmo especially
the only thing UI related is the fuel stuff..
i just took some time to layout everything and get some good X and Y values i can use for the main gameplay stuff
did you run the little initialization thing u need to run w/ dotween?
i ask everyone if their first time using dotween just b/c u never know
Thank you so much for all your help!
The window that popped after the import?
just wanted to make sure u installed the Sprites package
or physics2D if its a rigidbody.. but ur using transform.. so probably not
i created new scene with one 2d square with this script
void Start() { transform.DOMoveX(100, 10); }
but nothing happens
ok i went to preferences and reset it and now it worksπ
Hey Nav just wanna make sure your here just to not explain my problem again
ok Ill explain my problem hey guys so I made a script called a ladder and put a refeence on it to access variables from another script which is for the player and got a varibale called isclimbing by doing _player.isclimbing now i added a cube gameobject to the ladder prefap and attached a script to it and trying to acess the isclimbig variable again just like how I used it in the ladder script I tried to get a refrence from the playercontroller script but it didnt work so wanted to ask for your guyses suggestions
if there any confusion please let me know and I will explain again
does that script reference the player? _player ??
"didn't work" is extremely vague and unhelpful
Show us exactly what you tried and what happened when you tried and how that differed from your expectations
so my goal is to get a reference to the bool in the player script i did this in the ladder scriptprivate FirstPersonController _player; _player = other.GetComponent<FirstPersonController>();_player._isclimbing = true; and I succeded in getting the varibale from the ladder script now I tried to get the bool to the cube I added to the ladder prefab which has a different script one sec let me get it
showing the actual code would be better than an unformatted runon sentence
i dont know if it would work but did u determine the bool as public?
!code
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π 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://paste.mod.gg/qmvpptzznrwr/1 here can u access it
A tool for sharing your source code with the world!
Yes now can you explain what's going wrong with this code?
so the other script I believe I called cube thing in link you gave me i cant acess the _isclimbing variable
other.GetComponent<FirstPersonController>();
what do you think other is in the context of this Start method?
Why don't you show us the code that's not working
you need to share the code that's not working
it is in there
and explain what errors you get
arent there two tabs
Yes I see it
can you explain what's wrong with it
Are you getting an error?
It wont let me acess the variable it keeps telling me that the first person controller is unrecognizable
read and share the actual error messages you are seeing
this is too vague
your not the first person to tell me this Im am from the middle east Ill get there and be good at it give me some time
The actual precise error message is important.
Read the error
see what it says?
"Are you missing a using directive"?
Notice in your other file you have this:
using StarterAssets; // to access FirstPersonController
that's called a "using directive"
since that other class is in a namespace, you need this to use that class here.
Also - your IDE should be automatically suggesting to fix this error for you
If it's not doing that, you haven't configured it properly
I couldve sworn that i did that Just put it in now its telling me this now
What is other
hey does anyone know why when i instantiate a UI text its not showing on my screen, i checked the postion and everything is fine, but for some reason the text is just invisible and im not sure why
Is it a child object of a canvas?
Im not sure I thaught thats how u get access to another script
yes
well
no
because i turned it into a prefab and deleted it from hierarchy
Where do you define what other is
So when you spawn in the object, it needs to be a child of a canvas
so how do i do that
Look up the different parameters for Instantiate and see if any of them might help you set a parent
Im not sure what other is for at my current stage i thaught it was how you get acess to another script like name it and then do the other thing
where should i look in unity documentation for that, just search "parent" or "instantiate"?
Look up the Instantiate function
this isnt working and idk what button it is
no, it was a parameter for the OnTriggerEnter method you used in the ladder component. if you don't understand how c# works then stop what you are doing and go learn the basics. there are beginner c# courses pinned in this channel and the pathways on the unity !learn site are a good next step after that
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
the other is from the ontriggerenter method
You're going to need to actually say what isn't working about it
ohhhhhhhhhhhhhhhhh
okay so it isnt appering and idk what to do
What isn't appearing. Remember, we cannot see your screen. You have to actually say things
start be like who tf is "other"
this reminded me of blue prints from unreal
the pause menu
maybe try GameObject player; and then player.getcomponent...
Okay and what is supposed to be making it appear
you should take a look at #854851968446365696 to see what you should include when asking for help
or maybe look up some tips on how to ask questions
the pause menu
Okay and what is supposed to be making it appear
this
Okay and what is supposed to be making it appear
Then why do you expect it to appear
idk
@shrewd gazelle did it work?
but what button should i do or do i send the script to see
So, figure out what you actually want to do and what is happening then try again later
working on it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class pause : MonoBehaviour
{
public GameObject pausemenu;
public string sceneName;
public bool toggle;
public SC_FPSController playerScript;
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
toggle = !toggle;
if(toggle == false)
{
pausemenu.SetActive(false);
AudioListener.pause = false;
Time.timeScale = 1;
playerScript.enabled = true;
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
if (toggle == true)
{
pausemenu.SetActive(true);
AudioListener.pause = true;
Time.timeScale = 0;
playerScript.enabled = false;
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
}
}
public void resumeGame()
{
toggle = false;
pausemenu.SetActive(false);
AudioListener.pause = false;
Time.timeScale = 1;
playerScript.enabled = true;
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
public void quitToMenu()
{
Time.timeScale = 1;
AudioListener.pause = false;
SceneManager.LoadScene(sceneName);
}
public void quitToDesktop()
{
Time.timeScale = 1;
AudioListener.pause = false;
Debug.Log("the game will quit");
Application.Quit();
}
}
thats the script
!code
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π 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.
is there anything for button
i know how to code but i cant find a button thing
but do you know how to read?
yea unless i cant spell that word
because if you do, you would see that was not instructions to learn how to code. it was instructions for how to correctly share your code
but apparently you don't understand the words that are being said to you
sure then
okay so i was looking at the documentation and the different parameters for instantiate but cant find where to put "parent" into the code
You would pass it to the Instantiate function, like you have every other parameter
inside of the ()?
im sorry im pretty new to this so some of the termonology is a little confusing still
FIXED
Im a bit confused on how can I access the script called FirstPersonController
https://unity.huh.how/references
and if that is too much for you to understand then: #π»βcode-beginner message
not gonna lie I only read the first part of your message but I did this style in unreal and the way i learn is do and then when i get stuck get help from experts and then keep practicing it thats just me becuase no tutorial is gonna cov er everything u encounter in a project imo
alright well then i'm not helping you any further. i do not help people who refuse to actually bother learning the basics
dude I watched an entire udemy tutorial
Ill show yo if you want they dont go into specifics
this something that you learn in a project
and yet you're still just blindly guessing at how the code works
If the way you learn is by doing then why are you asking us
public GameObject player;
firstpersoncontroler _player;
in start method
_player = player.getcomponent<firstpersoncontroler>();
if not working maybe try
_player = getcomponentinchild
or
_player = getcomponentinparent
if you read my message I said doing getting help from experts and then practicing it
it is entirely unnecessary to have a second variable for this
Well you can't go more expert than the people who made the engine !learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
Im confused
If I want to get something in a list by index how do I do it
just use the indexer on the list? just like you would an array because that's basically all a list is
Oh ok thanks
Ghassan in The 2nd or 3rd metod u dont need The Player gamΔ object
Tell me it it works
they don't need the player gameobject variable at all because it is entirely unnecessary
if they can drag in the gameobject anyway then they can just use the correct type of variable and not bother with getcomponent
if i try https://social.services.api.unity.com/v1/names/{playerId} with a wrong playerid it returns a not existing playername. Any idea how to check if a playerid exists?
also consider reading the documentation
ahhhh i figured it out now tysm
Unfortunately, I have not found anything about this. You can also add friends if the PlayerID does not exist.
questions regarding the gaming services belong in #archived-unity-gaming-services
dude lol I made it work and all i did was i wrote ther name of the script I wanna access and then gave it a name where you decalre variables and then made a function so I can acess the bool I wanted without runing into any issue and it workedπ
justr wanted to share that with you becuase you helped alot
Thanks
And the info about the other. Component was an eye opener not gonna lie @slender nymph
Wow this feels so good after a day and half a day and half of trying to get this π
{
change.x *= m_Data.YawSensitivity;
change.y *= m_Data.PitchSensitivity;
Vector3 euler = m_SpringArmKnuckle.eulerAngles;
float yaw = euler.y;
float pitch = euler.x.Remap360To180PN();
pitch = Mathf.Clamp(pitch - change.y, m_Data.MinPitch, m_Data.MaxPitch);
Quaternion yawRotation = Quaternion.Euler(0, yaw + change.x, 0);
Quaternion pitchRotation = Quaternion.Euler(pitch, 0, 0);
m_SpringArmKnuckle.rotation = yawRotation * pitchRotation;
}```
for some reason my spring arm is only rotating the yaw and not the pitch and i dont know why
I'm assuming the answer is yes, but can you can call OnDestroy() when just destroying a script component, not the whole object right?
idk why you wouldn't be able to but OnDestroy often makes me scratch my head as it is
like if you destroy a component does it call OnDestroy method on that component?
ig yeah a silly question
Are you talking about Destroy or OnDestroy?
I only found out today that you can destroy a class
You don't "call" OnDestroy, unity calls it automatically
oh ok
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/MonoBehaviour.OnDestroy.html
doc says it on the first line
Destroying the attached Behaviour will result in the game or Scene receiving OnDestroy.
i meant if you destroy a class, is OnDestroy called
Components *
script component* right
what is the actual difference between the two
or is it just right terms but essentially the same
components are scripts you put on gameobjects
component is just fancy word for object attached to a gameobject
{
change.x *= m_Data.YawSensitivity;
change.y *= m_Data.PitchSensitivity;
Vector3 euler = m_SpringArmKnuckle.eulerAngles;
float yaw = euler.y + change.x;
float pitch = euler.x.Remap360To180PN() - change.y;
pitch = Mathf.Clamp(pitch, m_Data.MinPitch, m_Data.MaxPitch);
Quaternion yawRotation = Quaternion.Euler(0, yaw, 0);
Quaternion pitchRotation = Quaternion.Euler(pitch, 0, 0);
m_SpringArmKnuckle.rotation = yawRotation * pitchRotation;
}```
does anyone know why its rotating the yaw but not the pitch
You wouldn't be able to call Destroy() on a Poco for example
needs to be UnityEngine.Object (component though specifically or gameobject)
Log the final pitch value
Then find out why it is probably the wrong value
i see, thank you
@faint osprey It's usually better to keep track of your angles in separate floats instead of reading from euler angles
(0.70091, 0.00000, 0.00000, 0.71325)
its just that no matter how much the mouse moves up or down
Quaternion yawRotation = Quaternion.AngleAxis(yaw, Vector3.up);
Quaternion pitchRotation = Quaternion.AngleAxis(pitch, Vector3.right);```
can get rid of euler there and just use AngleAxis
ill try that
That won't fix it
was just a suggestion, not a fix
have you verified that your angles are in the range you think they are?
e.g. by logging the yaw and pitch values
idk what the range is tho
cause the min max values are in 0-360 and the pitch is -180 to 180
how do I write an IF statement to check if the current scene is a certain int
now you have an integer to work with
hello, how do i make public lists like this? Kinda where you can have your own public variables INSIDE of the list items.
i couldnt find an image where there was dropdowns for each item but i hope i explained what i mean well
If you have a list of a class, you'll get a foldout for them. If it is something like an asset, you won't without third-party editor extensions.
alr
how do i add a class to a list
tbh, i dont even really understand classes
yay
thanks
Should I use animating colliders or multiple raycasts if I want to make melee swing?
my personal opinion would be atatching colliders to the melee that's being swung
Hey everyone this might be a silly question but I am trying to use a canvas for the UI of my game but it is leaving a huge line in the middle of it. Why is this happening?
Thatβs showing you the rectangle of the canvas.. ie the screen
how do i fix this
just made a new project and a new script and Visual Studio is no longer showing errors or anything - they only show up in the Unity console
any idea what might have happened?
I tried restarting VS a few times
but that didn't help
What the "this" that you want fixed?
Your !ide is not configured.
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
my question is how though
its been configured for over a year and now suddenly isnt
its also configured on the project i was just working on before this one
Hard to say. Go over all the setup steps and see that they're correct.
It happens. In Unity, Preferences -> External Tools -> Regenerate project files tends to sort it out
You can go ahead and make it move, and kill and what else
That's not something we can do for you
i try it dont work
Well thats gonna have to wait my GPU just crashed lol
I guess that's the end of the line then
what
You provided literally 0 info on your project, the issue and what you have tried so far. We can't help you without it.
do i send someone the project then to help fix it
No. Provide a proper explanation and relevant code. We still don't even know what the issue is. And know nothing about the context of the issue
so i added the code for walking and moving but it dont work and i dont know what to do
No, the correct way to present these problems is first try everything you can, and when you encounter a specific issue you explain clearly what that issue is and how you're trying to overcome it, then it's possible for us to help
Great, share info on your setup and the code then.
i already tryed
the full script
Use the code formatting to post it this time
If the whole script is relevant, yes. !code
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π 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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Obunga : MonoBehaviour
{
public NavMeshAgent ai;
public Transform player;
Vector3 dest;
void Update()
{
dest = player.position;
ai.destination = dest;
}
}
why did it send
Read the bot message above
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class obungaJumpscare : MonoBehaviour
{
public Animator obungaAnim;
public GameObject player;
public float JumpscareTime;
public string sceneName;
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
player.SetActive(false);
obungaAnim.SetTrigger("Jumpscare");
StartCoroutine(Jumpscare());
}
}
IEnumerator Jumpscare()
{
yield return new WaitForSeconds(JumpscareTime);
SceneManager.LoadScene(sceneName);
}
}
jumpscare
Stop
why
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π 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.
what do i do with that
Read it goddamit.