#⚛️┃physics
1 messages · Page 79 of 1
I fixed it, the script I was using it wasn't working properly
anybody got a spider-man webswing thing?
I found some resources on grappling hooks, I guess thats a good start.
so i'm making a weather and climate model
it's for mecha_moonboy's game if he's mentioned it much here
it's not too far along yet, still working on getting solar heating right
what'd be the best way to make a character controller interact with rigidbodies? I was using this approach but by doing it this way there's no influence from the rigidbody's size at all. How would I be able to achieve that effect?
void OnControllerColliderHit(ControllerColliderHit hit)
{
Rigidbody body = hit.collider.attachedRigidbody;
if (body == null || body.isKinematic)
return;
if (hit.moveDirection.y < -0.3f)
return;
Vector3 pushDir = new Vector3(hit.moveDirection.x, 0, hit.moveDirection.z);
body.AddForce(pushDir * pushPower * (speed / 2), ForceMode.Impulse);
}```
so I have this code that makes a bullet bounce off walls using ray casting. It works 90% of the time but sometimes a ball or too will just teleport through the wall. The first line makes the bullet move and the rest is the ray casting. Does anyone know why this is happening and how I can fix it?
ForceMode.Impulse will take into account rigidbody mass, not size
so what'd be the most accurate way of making them interact?
for example, when two rigidbodies interact, what exactly happens?
What you did looks okay at a quick glance. What doesn't work ? You don't like the result you got ?
If you wanted a result relative to size, you would add it into the equation, like you did for speed
Hmmm
I see
But just to clarify
I had an impression that rigid bodies would be harder to be moved by other rigid bodies depending on their size
Isn't that how it works?
Oh good question
Never used rigidbodies with much of a difference in size so can't really tell 😛
But now I want to know too 🙂
hmmm this looks interesting https://docs.unity3d.com/ScriptReference/Rigidbody.SetDensity.html
But I just discovered it now so can't tell if useful
I didn't quite understand what that would do
OH okay I get it
But wait, does that happen by default or...
Okay so I have no idea what Im doing atm, but how do i rotate my rigidbody?
rn im rotating the object using transform.Rotate() but my rigidbody.AddForce (or rigidbody.velocity that I used previously) is still moving in the same direction
AddRelativeForce doesn't work as it reaches hyperspeed and becomes extremly glitch
nvm found a solution. copied a piece of code from another project and modified it a bit
Vector3 direction = transform.TransformDirection((currentVel + currentNitroVel)-rb.velocity);
rb.AddForce(direction - rb.velocity, ForceMode.VelocityChange);
anyone know why?
actually, it glitches out a lot if i rotate it a lot
why do the physics joint give me a null reference exception if i just add one to an object?
When i used them last time this didn't happen
But it's been a while
I would reboot my editor
ill try it
so I finally gave up on using traditional wheelcolliders and switched instead to this raycast implementation: https://github.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/blob/master/Assets/Scripts/RaycastWheel.cs
the problem i'm facing now is it seems to just slowly slip backwards and no amount of adding equal rigidbody force, messing with slip values, etc seems to solve it. notice the Z value in the top right: https://i.gyazo.com/fbd493642a6ea2b54b0cd8cf32263a55.mp4
I am working on making a wire using Config Joints. And one of my big issues is that the joints seem to drift apart even though movement is locked. Anyone have any ideas?
any ideas why is my rigidbody not colliding with other objects? they all have box collider and they are not triggers
what kind of collision are you expecting and what are you seeing instead
And how are you moving said objects
How can i prevent my hinge joint to effect connected body? I just want it to follow like parent-child and turn around it when i press some key
Hi. how to do edge collider alternative in 3D?
I want to have 2 points and between them a cube with collider. please
What is .maak
can you elaborate? can't you just use primitive colliders such box collider for the cube?
I've tried to use primitive boxx collider but couldnt do it
I want to drag positions with mouse
and Down position will be A point
Release Position will be B point
in 3D
and want between box collider
._> idk how to do
fixed
I have a quaternion rotation of object X
How to get quaternion rotation that is supposed to be rotation of bullet, assuming they come from center of object X?
without transforming into euler (if possible)
transforming from euler is fine tho
so im expecting for it to hit a sink then fall into the floor
but its just falling and going through them
and im using a rigidbodu
rigidbody*
Please show the inspector window for the two objects you are expecting to collide with one another
im not home yet ill do it as fast as i can
Is there a way to addForce to a rigidbody across two axis simultaneously (i.e. diagonally)?
Currently I’m using addForce.forward, addForce.right, addForce.back and addForce.left. This works sufficiently for moving along one axis, but doesn’t apply force along two axis
You can pass in any vector that you want
Including one that is pointing diagonally
I’ve tried using addForce(1,0,1) for example, but then there’s the issue of velocity
I’ve also tried Input.GetAxis and can’t seem to get that working properly either
For whatever reason the gameObject either refuses to move diagonally or has inconsistent velocity
wdym by "the issue of velocity"
If you have other code that's explicitly setting the velocity, AddForce isn't going to work right
the only effect of AddForce is to change the velocity
It seems to be multiplying the values, so moving diagonally increases the speed at which the object is moving
multiplying? No, but (1, 1, 0) is in fact a longer vector than (1, 0, 0) for example
so it's more force overall
The magnitude of (1, 1, 0) is sqrt(2) (aka like 1.44 something), while the magnitude of (1, 0, 0) is 1
So in that example, would a solution be to use (0.5f, 0, 0.5f)?
no
(1 / sqrt(2), 0, 1 / sqrt(2))
or just
(1, 0, 1).normalized```
or cs Vector3.ClampMagnitude(new Vector3(1, 0, 1), 1)
rb.AddForce(1,0,0).normalized; throws up an error
course it does
AddForce doesn't return anything
there's nothing there to normalize
you make your vector and pass the normalized version of it into AddForce
Vector3 force = <whatver>;
rb.AddForce(force.normalized);```
Okay, so for instance
Vector3 right = new Vector3(1f,0,0);
rb.AddForce(right.normalized);
Now this works better
Still seems to be moving faster diagonally though
Show code
Now I'm sure that it's user error on my part, and I'm also sure there's a way to optimise this code, possibly using GetAxis
Yeah you're separately adding each direction so your normalization of the vectors is useless
Using GetAxis can certainly simplify this a lot but the idea is you should build up a single Vector2 and then finally normalize that and call AddForce with it one time at the end
Also AddForce should not use deltaTime
Your use of deltaTime is why you need such a high value for "speed"
Okay that makes sense
Yeah that's working a lot better
Thanks (once again) for the help @timid dove
I guess I can also lose the Time.fixedDeltaTime
I got a question guys but I don't really know where to post it, I think this is the closest it would relate to
I'm trying to make a flip counter for this snowboarding game, I figured I'd have a hit box on top of the player (flipbox) and if the board's hitbox touches the flipbox it will count as a flip however my flipbox does not follow the character perfectly, it sorta lags behind, does anyone know how to fix this?
I remember having a similar problem before with my character I just can't remember how I fixed it
Hi all,
I'm trying to make sense of mesh colliders being used on very large mesh objects. Everything I read online says to avoid them, but very few specifics or benchmarks are provided.
In the case of a static mesh object where each mesh face is fairly large compared to a character's size (let's say 2x the width at least), do we get away with using them?
I'm imaging low poly terrain ideas, except with very high poly models being used for terrain. (It's not always easy to segment large mesh models, and the renderer seems happy with veery large models.)
A mesh collider with 50-150k triangles would be extremely useful to me, and it seems to work?
Is anyone familiar with this concept?
Thanks!
did you fix it?
how do you move the hit box?
No I didn't fix it yet, started working on some other coding stuff. I had the idea to move the hitbox by placing it as a child of the Cinemachine Follow Camera on the Player
I remember doing some setting that smoothed out the camera on the player, not sure if there's a similar setting or something I could do to mimic that with the hit box
I'm super new
In the middle of taking the 2D course online on Udemy lol
I have no clue how I'd do that
You're saying have the hitbox itself follow the player?
yes
hitbox.transform.position += player.transform.position + offset;
offset being a vector3 that you set in the editor
So offset would be a serializedfield?
yes
That is basically the idea I had lol
gg
Thank you
That single line of code would have taken me ages to figure out
@nocturne fern I'll ask over here as it's a tangent, what in your view is the problem of using RigidBodies for FPS movement and what do you view as the correct alternative?
There is a bit of a clarity issue because there is no official best type of movement for each kind of character, so every tutorial tells beginners to use something different
Anyone know any good reading on how to prevent a character controller from clipping through walls at high speeds?
Thanks! I guess I wrote a really shitty version of a sweep test, but the above will help me (hopefully) make it a bit better 🙂
for a character you would probably use https://docs.unity3d.com/ScriptReference/Physics.CapsuleCast.html
Something I'm not sure on, is if I catch high speed collisions with a raycast, how far should I move the character into the wall to enable sliding?
My game is grid based, so I'm stopping at the hit, then moving velocity into the wall, with a maximum of 0.5 (half a grid)
That seems to work pretty well, but If I hit an edge at very high speed it's a bit weird, but probably fine
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
Hmm what would happen if you ended up inside a wall with the above approach?
you need to check the slide vector as well, so you dont slide inside something
pretty sure you can find lots of info about how its done in various older games (like quake3 etc)
code is also available. doom 3 has some very advanced physics etc
full CCD for everything IIRC
Rigidbodies are designed for things that are driven by Unity's physics system. When there are behaviors from the physics engine that you do NOT want your character to experience (such as bouncing) you essentially have to work AGAINST the physics engine to override that behavior. You do not have the same precision with a rigidbody's movement that you do with a character controller. This adds up to a lot of work.
Character Controllers on the other hand are designed specifically to drive characters with movement typical to what you would expect in most AAA titles where they glide across the floor naturally. You do have to code in special cases like jumping/gravity but I did both of these things in 150 lines of code which is nothing.
Another side effect of using rigidbodies for FPS is that your rigidbody is moving on FixedUpdate which is every 0.02s (technically, it runs 0.02s worth of physics simulations for every block of 0.02s that has passed, it doesn't actually run exactly every 0.02s). The issue with this is the camera will be really jittery if you put it in fixedupdate as well but if you put it in update and you have your rigidbody moving in fixedupdate they will move at different points and you will get a camera jitter. This is not extremely noticible with a third person if you do some hackery. But in an FPS game...this is really bad.
The only games where rigidbodies are technically proper is games like Human: Fall Flat where you actually want this bizzare behavior. Maybe some other 3D adventure games where you care more about how the character moves visually than you do about giving the player precise controls. Many 2D Unity developers use rigidbodies beccause its easy to set up in 2D but its technically not proper. No other game engine defaults to using rigidbodies for player characters. Basically every other engine uses character controllers.
I guess one newer phenomena is some people are starting to use root motion exclusively to drive character movements. I wouldn't say its common but I know its out there.
Basically, character controllers don't even use the physics engine aside from collision detection and correction. Sidenote, the lack of a proper character controller in DOTS is one of the main reasons I haven't moved over to DOTS. They do technically have a character controller...but it's not done well...
How do i sync ball rotate and move when rolling? I mean this ball should be rotating
And that should be moving
Any system is "proper" as long as it does what you need. If you want physical forces to act on your player, be it an FPS or not, Rigibodies are the most convenient option. Sure you do have to put some work in to stop unwanted behaviour but if physics are the goal it's still better than coding physical forces from scratch as you would have to do with a Character Controller.
I don't have any particular beef with Character Controllers but it's baffling that they don't have gravity and jumping from the get-go. 150 lines for something that should be a given is a lot asked from someone who just wants something that works, especially a beginner.
The FixedUpdate thing is a non-issue. You're expected to enable Interpolation on Rigidbodies and the stuttering is gone.
If I see beginners using Rigidbodies incorrectly it's usually because they've learned from tutorials to move using Transform.Translate and in Update loop no less.
You don't generally need to "sync" it
If the surfaces have friction the ball should roll
What kind of colliders are they with what kind of physic materials
ty, i thought ball friction would be enough, didn't think about the surface
how is the unity wheel collideres friction simulated?
im trying to make my own physics car system and i wanna make friction so just curious
They don't have gravity and jumping because not all character controllers can jump or are affected by gravity. Jumping and Gravity are not actually 150 lines of code, they're like 3 lines of code. It's acceleration/deceleration/turning boost that takes 150 lines of code. If you just have doom controls where input directly sets velocity to some value than you can do all of this in like 30 lines of code. I actually take major issue with Unreal Engine's character controller because it does way too much (UE's actually has full network replication support out of the box and such which is why their character controller and movement code is tens of thousands of lines of code)
You will never get amazing character controls with a rigidbody in an FPS game. Either you have the camera only updating its position every 0.02s or you have the camera moving at different times than the player.
Of course you can hack any code to 'make it work' but I'm just saying there is a reason that literally no other game engine is even set up for the possibility of driving your character through the physics simulation. It's one of those things where the Unity community says "do it this way" but Unity devs are like "Uh, that's not what its for". Unity is pretty varied in what kind of games it can make. If your player is a ball in a pinball game than yea, you would technically have the player driven by a rigidbody. But if you're making something like an FPS or an Open World RPG or Open World Survival style game...character controllers should be your default. The amount of AAA titles that use rigidbodies (or other methods driven by the physics simulation) in these genres is approximately zero.
Yea it sucks you have to add code but...you can't go very far in Unity if you don't get used to coding things manually.
How can I stop my car from slipping on the terrain every time it turns?
I can't seem to get a hold of the friction modifiers
Any help will be appreciated
Why's it an issue if the camera is using the body's interpolated location?
Most open world style games have basically entirely static worlds and don't need accurate physics on the player. Triple-A games have the resources to code in all interactions and edge cases that the physics engine normally would take care of, and they're basically all using root motion with their mocap'd animations anyway.
It seems to me you're making a lot of assumptions what player movement should be like. The only relevant question is: does the tech work towards the project's goals?
By coding interactions I mean stuff like how the player reacts being pushed, sliding down slopes or being hit by falling rubble. Not every project has those, but it's really nice that Rigidbodies react to all of that without any sort of extra work.
That kind of flexibility goes a long way when you're prototyping or just starting out and don't necessarily have the time or motivation to implement all of it manually
From my experience unity devs don't really give any official advice how to use techs like this, but if they didn't want Rigidbodies to be used for characters they should've made physical forces be an option for Character Controllers
my question as well lol
if you're using wheel colliders you can't use friction material
*physics material
if you're using like a raycast system you can't do that either i think
In a third person game I don't think the camera issue really manifests but in first person games it's fairly blatant. I AM making assumptions about what player movement should be like because we have a very long list of games that have handled character movement a certain way and while deviating from this can be innovative how many developers actually even want to be innovative when it comes to how player movements are handled? If you're not trying to do something unique when it comes to the character's movements, use a character controller so it feels natural to your average player.
I'm not saying you should never ever use a rigidbody as a character controller...but again specifically in 3D humanoid style games, there's very few genres where a character controller is not the best option. Overwatch doesn't want players moving around like ragdolls (except when they're dead).
Using Rigidbody doesn't mean the character is some kind of ragdoll that's loosely fumbling over furniture.
I think you may have a misconception about how Rigidbody characters can behave. If the physics steps are interpolated and the object is constrained to stay upright, the user will not be able to tell what code is running underneath
Common or conventional doesn't equal good either
How many triple-A open world games in recent years have been notorious for their glitchy character movement? In first person games being able to glitch your character out of play area with a physics object is so routine that players are not only not surprised when that happens, but expect it
If you do both of those things you will still have an immediate problem where when the character hits a small object on the floor they will bounce upwards like a ball and flop back on the ground. There is a way to get rid of this behavior but this is what I'm saying...you're working against the physics simulation and essentially undoing everything the rigidbody does to take advantage of like 5% of what the rigidbody does instead of just recoding that 5% into a character controller. In this particular example you end up having to undo the rigidbody behavior and then end up programming step up controls which...the character controller already does for you. So you're putting in extra code to get rid of rigidbody behavior and then putting in more code to do what the character controller already does...
And rigidbodies introduce a lot more glitches than character controllers. Just look at Skyrim's character controller vs the objects that you can move around that are controlled by their physics engine....
Interaction with various physical forces is a lot more than 5% as you'd have to code every type of interaction separately, but again that depends on the project. It hardly makes a difference in the end whether you're coding against the physics engine or coding up all the features Character Controller doesn't have.
The Controller handles horizontal movement and slopes and that's about it? The real tragedy is the coding you'll have to do either way just for something so basic
Everything about Skyrim and its engine is glitchy so I don't think that proves much 😄
That one can't even reliably flip quest flags without losing them to cosmic background radiation, apparently
My 150 line movement code does basically everything Skyrim's character does.
The character controller Unity provides does all the collision stuff. It resolves collisions, handles sliding against a wall, provides step up control. Yea, making a character controller from scratch would be a lot of work but using Unity's and just coding the behavior is not that complex.
Skyrim's engine is fine, it just gets a bad rap because they put a bunch of crappy assets and scripts into it. People associate bad animations with the physics engine and they associate crashes with the engine crashing when its usually their scripts causing the crashes. The modern Gamebryo engine is actually pretty great, but they deviated from it years ago and have been patching it as they go. It provides high graphical quality and works quite well, but garbage in garbage out.
I've always thought of its character physics as one of the floatiest and glitchiest on the market, but that's off topic
That's just their settings on the character controller - I think they have a really low gravity value and such which makes it feel weird but its not the engine its their implementation. Now the physics simulation is bad by modern standards yes which is why objects that collide go flying.
That and how the edges of the character seem to strangely stick to things when you try climbing anything
Guessing you're programmer by background if coding missing features in bothers you less than reining in pre-existing ones
Might even give a sense of control as you can decide how to build it
Or maybe your projects don't need complex interactions
Either way, I've tried making various types of characters with Rigidbody movement, Character Controller movement and some without either
My only takeaway is that all of them are just a miserable amount of work to get working nicely, but also that depending on the project none of them are better than the others
Which is kind of a weird contrast compared to how much unity's navmesh agents offer with out of the box functionality
They even got jumping while Character Controllers did not
I will say I am very controlling when it comes to code. The reason I'm using Unity and not Unreal Engine is I constantly get frustrated by the handholding in UE when it leads me down a way of doing things that I don't agree with and deviating from said path in Unreal Engine is a nightmare because coding in UE is...ugh.
if you have a kinematic rigidbody - can you move it via transform position without issues ?
Use MovePosition if you want it to realistically push other rigidbodies
i dont want any collisions on it
but it seems to still collide even when i have kinematic on
and im using transform.position
If you don't want collisions remove the Collider
well i had this:
public void PickUp()
{
_rigidbody.isKinematic = true;
_rigidbody.angularVelocity = _rigidbody.velocity = Vector3.zero;
_rigidbody.detectCollisions = false;
}
public void Drop()
{
transform.SetParent(null);
_rigidbody.isKinematic = false;
_rigidbody.detectCollisions = true;
}
so when i pick it up its still colliding with things
Is it Rigidbody or Rigidbody2D
3D
let me make a gif
Or other objects are affected
it seems to collide when i pick it up from the table but pickup is the function shown above
so i don't know why it glitches out like that, some times it frees itself however
Show the rest of the code
this is the RB of sphere when its glitching
and okay let me get rest of the code
private void TryPickUp()
{
var pickable = _pickables.Nearest(); // get nearest pickable object
if (pickable != null) // we found something
{
_holding = pickable; // set nearest
pickable.PickUp(); // calls object to update rigidbody
//set the pickable object as a child so it follows player
_holding.transform.position = _holdPoint.position;
_holding.transform.SetParent(_holdPoint);
}
}
// pickable.PickUp();
public void PickUp()
{
_rigidbody.isKinematic = true;
_rigidbody.angularVelocity = _rigidbody.velocity = Vector3.zero;
_rigidbody.detectCollisions = false;
_collider.isTrigger = true;
}
@timid dove here u go
That's not the rest of it
The whole script ideally
do you need the drop code aswell?
theres only 4 functions, pick up and drop
2 on the player 2 on the objects in question
So you move by parenting
yes since its no suppose to be subject to physics anymore
That should work fine 🤔
thats why i dont understand why its glitching on my table
Show drop code please yeah
okies
// player drop:
private void DropObject()
{
if (_holding==null) return;
var dropOffPoint = _dropPoints.Nearest();
if (dropOffPoint != null && dropOffPoint.PlaceItem(_holding))
_holding = null;
else
{
_holding.Drop();
_holding = null;
}
}
// object drop:
public void Drop()
{
_collider.isTrigger = false;
transform.SetParent(null);
_rigidbody.isKinematic = false;
_rigidbody.detectCollisions = true;
}
and the place item for drop off point:
public bool PlaceItem(Pickable item)
{
if (CanPlaceItem(item))
{
item.transform.position = Position;
item.Drop();
OnItemRecieved?.Invoke();
_item = item;
return true;
}
return false;
}
Seems relatively straightforward
yeh - its why i am confused why its colliding with my table
kinematics shouldn't do that
it correctly set the parent aswell so its trying to move with the player
unless its some physics bug ive discovered
Does the sphere have any more components than this or any child or parent objects (other than the hold point)
it has no children. it only has a parent when its a child of the player when im holding it
if i drop it the parent is null and so its free to be physics based
Also do you get any warnings about collision detection modes when it becomes kinematic?
no i get no warnings unless i need to enable some more advanced warning logging some where to see that
_rigidbody.MovePosition(heading.normalized * _moveSpeed * Time.deltaTime + transform.position);
Vector3 orientation = Vector3.RotateTowards(transform.forward, heading, _turnSpeed, 0.0f);
_rigidbody.MoveRotation(Quaternion.LookRotation(orientation));
thats in fixed update
Hmm
Do you have any listeners for OnItemReceived
no i've not implemented that yet
What's the parent when this happens
I'm pretty stumped TBH
same lol
you're welcome to try use those functions to see if you reproduce the problem
Maybe tomorrow. It's pretty late here.
@timid dove i thought i had a solution but guess not. i assumed that its collider was being considered for the player's RB even though the RB of the item was kinematic, but disabling the collider still causes issues so i guess thats not it either 😦
fixed it
had to stop making it a child of player
no idea why but oh well
Hello. should we use deltatime in FixedUpdate, when trying to move (or addforce to rb)? and should we use it when we are setting rb.velocity =?
No
I want to set velocity of rb and then ball will start bouncing on the edges of screen. When I'm doing it, velocity is deccreasing afterr every collision. I want to remain constant speed. (or just speed up after time)
And what is the usage of Time.fixedDeltaTime then?
It tells you the time interval between FixedUpdate calls and physics simulation steps
Time.deltaTime does the same too but not in fixed intervals and I use it when I try to move obj via transform.position
and I wonder whether Time.fixedDeltaTime is used in same way but when trying to move rb
deltaTime in FixedUpdate is exactly same as fixedDeltaTime (0.02 by default)
Yes. But where can I use fixedDelta. where should I multiply it
Only if you directly move the position which you shouldn't
MovePosition ig
Use velocity or add forces
and what happens if my phone can not comperhend 50 fps. and it dropped to 20fps for example
Doesn't matter
it's still 0.02
FixedUpdate will be called multiple times to catch up
it may not
It will be
it is trying but not always it is able to
Interesting. thank you. so I will never use deltaTime stuff when dealing with rigidbodies? (setting velocity.... adding forces or torques)
Unless you reach the max per frame in which case the physics sim is slowed on purpose
In any case it still represents the same fixed time interval
Not for those purposes no
Can you suggest what can I do here?
Just set the velocity manually
- I use 3D physics and rb pos Y is frozen
Set the magnitude of velocity yourself
and all rotatioons of ball too
Don't rely on the existing magnitude
That magnitude is always 40
I checked it
So what's the issue
Ehy
wait I can record a video
yes
Then it will be cut
Oh... interesting
maybe that's the point.
I have something like that
and want to bounce through walls. and since it 3D .. you might be right
that reflected vector should be only xz
You're ignoring the result of the projection
Yessyes. 1min
wow. it worked 😄
Thank you very much
Just one question
sometimes it stucks like this
what might be the problem?
it did the same thing.
maybe it is richocheting between that 2 collider
no.
It sleeps
Nvm. I think it wouldnt be problem. Thank you.
What are ways to prevent horizontal collisions in character controller?
rn I adjust velocity of character by doing collider cast in direction of it's velocity:
foreach (DistanceHit distanceHit in horizontalDistances)
{
horizontalVelocity += (distanceHit.SurfaceNormal * -distanceHit.Distance);
}
But, every time character goes into wall, it starts to stutter (like, 1 frame closer to wall, the other further)
skipping all hits with fraction <= 0 helps with walls, but
it doesn't help with corners:
same stuttering, characters clips through both walls (kinda goes left and right)
I assume it can be fixed by doing new cast after every adjustment, but I have a strong feeling that it can be avoided
how is the unity wheel collideres friction simulated?
im trying to make my own physics car system and i wanna make friction so just curious
hey,
hey?
Sorry hit enter instead of shift enter
You don't want to prevent horizontal collisions. Your character controller capsule is too small which is causing the mesh to clip inside the wall. Make the capsule larger and it will keep away from the wall.
The character controller capsule is the object from a collision point of view, the mesh is just a mesh that can collide through anything.
my mesh is exact size of collider (capsule) I use (for debugging purpose)
I aim to keep capsule collider for most applications
I want to prevent collision of collider with walls/corners, not mesh's
because as of now, character teleports back on collisions
which is extremely noticable
You're using the default character controller component right? Then you just use this component's .Move() function and it will automatically prevent collisions using the capsule defined in the component. You shouldn't have an actual capsule collider child.
Oh...
Yes dots...
This is why I don't use full dots...
They DO actually have a character controller in the sample pack. However, it's terrible because it integrates a bunch of features that you don't need, the input system never worked for me, and it's actually not even implemented with DOTS.
Quite frankly a DOTS character controller is someting that not even the devs have bothered to do yet so it's pandora's box. I made some progress and was able to resolve simple collisions but then I couldn't get the step-up and slide-against-wall code to work and went back to non-DOTS.
I would first look at the sample they included and see if you can make sense of it (it's bad though).
In the sample pack?
but wall sliding
no
but it's kind of based on sample one
Ah yes - I remember looking at this. I think the code was an outdated implementation of DOTS which is another reason I quit DOTS, it changes massively every once and a while - you could try contacting the blog author https://www.vertexfragment.com/about/
No gaurantee he'll get back to you, but the amount of people that know enough about modern DOTS and know the inner workings of character controllers in Unity (not just how to use them) is very small. A few months ago when I was attempting this I could not find a better source.
… Me My name is Steven Sell and I am a Software Engineer living in Tampa, FL.
I have over ten years professional experience in the Modeling & Simulation industry with special interest in Graphics, Engine, and Tools programming. My primary languages are (modern) C++ and C# but I am also comfortable with the following in varying degrees:
HLSL ...
Let me see if I can remember a research paper I stumbled on that was regarding custom character controllers...
I just need to figure out how to do collision correction correctly
for object sliding
it's same thing for both, dots and object based
Hmm
when I do collider cast into only 1 direction
for example 0,-10,0
my fraction*normalSurface would be vector that is parallel to my direction?
Anyone has any idea how to use dot product of quaternions?
Anybody know an asset that allows for floating balloons? Like air density / helium type of thing
Can't you just put a negative gravity scale?
Well you don't really need to code much
I think that property is even available in yhe inspector for rigidbodies
Doesnt seem #⚛️┃physics related
quaternions and dot products are the biggest physics out there
Hey guys, I have encountered one weird thing. I have Player object and I've set AreaEffector2D as child of a player to follow it
but, areaeffector2d doesnt seem to work when it's a child
any ideas how to fix this?
@wispy tinsel ig you can just yoink it from here (its actually same formula as dot product for vectors, no idea what that does and what would one do with it) https://github.com/Unity-Technologies/UnityCsReference/blob/master/Runtime/Export/Math/Quaternion.cs
no worries, already figured
I dont really see the connection… Editor codes and shaders also use dot products. Using that logic questions about dot product would fit any channel on this server…
dot product is pure geometery, but since we don't have channel specifically for geometery or even math, I think physics is the closest one
can someone please help in creating googly eyes?
yes for sure
i would need the version without script and with rigid body i think
Without script??? There's very little in Unity you can do without scripts
So question about input and movement, do I have to manually check that a collision hasn't occurred before moving the transform of the character? or does the colliders handle that for me, I know they handle that with regards to gravity, but what about walls?
If you move your object with forces, then the physics will handle collisions for you.
Ok. So then I don't move the transform, I let the forces handle that
That answers my question
Thanks
You don't want to move with transformation, no, it'll teleport it through colliders.
got it
@ionic dome You could boxcast, capsulecast
From startpos to end pos
And see where it hits a wall or see if it hits
Hi, i was watching a tutorial about car controller, and then the guy car flipped over and he changed the spring and damper values without explaining why. Now my car keep flipping and i cant find good values and his values did not work
Still stuck here
x.x
Hello.
Any idea on why physics break if the Camera stops looking at the physic objects? I have 2 RigidBodies interacting with a Joint and it works great, but as soon as the Camera looks away from it, when it looks back the physics changed in a way that the objects dont look right anymore
wdym don't look right anymore?
screenshots? Video?
Hi, I'm very new to unity and I'm in the middle of making flappy bird on my own. I currently have upper and lower walls to stop the bird from falling out of the cameras view, now the problem I'm facing is that the pipes collide with those upper and lower walls when I only want them to collide with the left wall (so I can spawn them back to the right of the screen). so can anyone help me with getting the pipes and the upper and lower walls to ignore collisions?
you can use collision layers
or set them to kinematic
and*
how do I do that?
you look it up :)
👍
@snow coral feel free to ping me if you can't get it working
Its working!!, but now I have a new problem, I wrote code so that when the pipes hit the left wall they get teleported back to the right of the screen, but that isn't working and I don't know why.
how did you fix it?
with the collision layers
how do I make an action happen only if a specific object is colliding with another specific object?
I've got a character with animations for locomotion, a controller, everything is working great. I add a Rigidbody and now he floats upwards slowly. The only changes I make from the default are to freeze rotation. It appears to use the capsule collider to update its center of mass, but why does it float away?
Use tags or layers or a component to identify the specific object
What are you hoping to achieve by adding the Rigidbody? It's not going to play nicely with the other stuff
I'm kind hoping to fall when I jump from platform to platform and miss. I was also after a ragdoll effect when I get shot at.
What is result of multiplication of quaternion and single float?
a scaled quaternion that is no longer a rotation unless that float was 1.0
I still struggle to understand how to correctly rotate quaternion without transforming into euler
my multiplying them
Basically, i have simple rotation to perform
let's say 90 degrees on Y axis
I create quaternion of Euler(0,90,0) and then multiply them?
and in what order then?
fooRotatedBy90 = fooRotation * Quaternion.Euler(0,90,0)
XYZ
in what way?
it says it rotates z x y
i think its perfectly clear
in that order
ZYX is the rotation order that is represented by the quaternion
you dont have to worry about that
it only matters if you do advanced quaternion manipulation or need to make them compatible with manual euler based rotations
I hope I don't kek
btw. if you use Quaternion.AngleAxis() instead of .Euler() its more explicit what your rotation actually is if you are doing stuff outside worldspace
I mean, I work with 2 different math systems which uses Unity.Mathematics
it's quaternion special
in what way?
no idea, but it's different
its just implemented differently for speed purposes
so you might have to deal with radians vs degrees or inputs need to be normalized to give you more control over when those operations happen
Nah, it is different.
Normal Quaternion clamping would be -90 to 90, while this quaternion forces me to do this pepega mode
x = (x > 200) ? math.clamp(x, 269.9f, 370f) : math.clamp(x, -10f, 90.1f);
at least, when I extract it to euler angles with Quaternion of UnityEngine
thats what i just said, it wants you to do stuff manually that the regular math does automatically because it may not be necessary in your particular calculations and thus provides optimization opportunities
i have dynamic friction of the floor set to .3 and the static to .5 but when i have a cube with a constant force in one direction, the cube will eventually start careening to the right
anyone know why
Is it hitting the edges of any Colliders? What's the floor made up of?
And how are you applying the force?
rb.AddForce(transform.forward * forwardForce * Time.deltaTime);
so this is for the cube movement
this is the physic material applited only to the cube
not sure if this helps
i seem to get a fix if i disable gravity
I want my character to walk over like this steps how can I make it
I figured it out. The animations I was importing from Mixamo need to have certain transformation baked into the pose. Now I have physics and animation in one character.
I have an Object that travels at a certain speed, lets say 400 m/s. I want this Object to decelerate and come to halt at an exact distance, lets say, 800m. Now I want to figure out the deacceleration (-acceleration). I have searched for formulas, but I only found this one: a = 2 * (Δd - v_i * Δt) / Δt². and I dont think it is the right one.
why don't you think that is the correct formula?
I have it from a website, and the description of the formula is this: "Use the Distance Traveled calculator. Enter the initial speed, the traveled distance, and the time that passed. You will not need to know the final speed."
Because I know the final speed, 0 m/s
And I dont know the time
Kinematic equations relate the variables of motion to one another. Each equation contains four variables. The variables include acceleration (a), time (t), displacement (d), final velocity (vf), and initial velocity (vi). If values of three variables are known, then the others can be calculated using the equations.
your gut about how to choose an equation is good
look at the 4 options under BIG 4 on that site
and find one that matches the variables you know with acceleration as the only unknown variable
thank you
Not sure if this is the right place to ask but I'm making a game where the player is running and fails if it hits an obstacle, like a fence, and I want the fence to fall when the player hits it. I set the player mass to 1 and the fence's mass to 0.0000001 and it still doesn't fall, just moves slightly.
I want to join (fixed join) 2 dynamic bodies, but able to rotate
such as a wheel joint but without any suspension. when the rigidbody is shifted, it shouldnt get pulled back to the connected, instead the other body should get pulled
Hello How can i find the velocity of a rigidy body relative to its transform and not like the world origin
transform.InverseTransformDirection(rb.velocity)
is that a vector 3
Yes
Guys, is there way to find out true velocity of the rigid body on collision moment?
I'm trying to get "relativeVelocity" from collision, but it's seems to be kinda random when I'm using it with VR. I'm punching with the same force in real life, but getting drastically different values. Please help if anyone knows.
i still have no clue my chair isnt colliding with the floor, here is the floor components:
and here are the chair components:
can someone help me please?
tysm!
So, my character model is set up with the input system, but for some reason it won't move left or right, just jump. But it's not the input system because the correct vector value is generated by the inputs, the character just doesn't respond to them. But if I perform a jump, the character jumps like it should.
So.... It's not enough force.....
hmmm
and it doesn't repeat as the button is held
Is your RB actually moving with velocity or is it simply being teleported around to match your VR controller's position?
So now the question is how to make the input continuous for direction
Hey Guys
Is it possible that when the ball rolls through the hole that the shape deforms so that the ball fits through?
If you use some kind of softbody physics simulation, sure
Unity doesn't have that built in though
anyone using the Havok Physics package ? the latest "Quick Start" guide mentions to get the package in the Package Manager with "All Packages" turned on. except, that dropdown option does not exist any more it seems ( using 2021.2 ), and clicking on the Asset Store Havok Page's Personal-Plan links to .. the Quick Start guide again 😐 wat
does that mean it's not possible to install the free personal version just for testing ? or am i missing something obvious
"Enable Pre-Release Packages" is on btw
what's the difference between continous and discrete collision?
This should explain it(read the accepted answer): https://gamedev.stackexchange.com/questions/192400/in-games-physics-engines-what-is-tunneling-also-known-as-the-bullet-through
@timid dove Thanks That cleared my doubts
hy! beginner here
for some reason my colliders dont seem to work correctly, and stuff can just go through each other for some reason
ive made two projects based on unity's official tutorials and both projects' colliders work fine on their tutorial video but not for me
i attached some footage of the 'go through' thing im experiencing. any help would be much appreciated
sorry for the poopish quality
are they on the same layer?
Are they on trigger?
Can you try to set the collision detection mode to continuous?
thanks for reaching. what are layers? as i said im a beginner and i only did the things unity's tutorial did and it worked fine on their side but not mine
i believe not
after some online searching, yes i have tried that with the car example but as you see it still goes through
what collider do you have on the car?
box, rigid body
how big is it?
its shaped like the mesh
i did not modified it
made a cube, scaled it, the collider is the same size
and i thought maybe its a 'my model' thing since i decided to make my own stupid car instead of using the asset store like the tutorial, but after the plane i realized its not about the models probably
should forces be applied where the wheel connects to the car
or where the wheel contacts the ground?
in the gif its applying them to the anchor point thats selected.. (the top of the suspension)
how are u moving the car
Transform.translate
Overview: In this lesson you will make your driving simulator come alive. First you will write your very first lines of code in C#, changing the vehicle’s position and allowing it to move forward. Next you will add physics components to your objects, allowing them to collide with one another. Lastly, you will learn how to duplicate objects in t...
im following this tutorial
well... transform.Translate isnt good for physics
whats happening is ur car is moving into the blocks before the physics get a chance to react an tell ya u hit them
for a rigidbody u should most likely use Rigidbody.AddForce()
to move it directly
now there is a work around..
u can move ur car using translate and then after u move the car set the carCollider (which would be on a seperate layer) to the cars new position..
in the start u could unattach it if its a a child of the car..
boxCollider.parent = null;
and then
after ur move function
boxCollider.transform.position = car.transform.position;
yeah i mean my problem is how come in the tutorial it works just fine...
and then use interpolation on the rigidbody to smooth out the jerkiness ull most likely git
idk ill have to take a look at it
i tried getting it working with AddForce but for going backwards the car just flips over
i just started out. so even figuring out AddForce syntax took a bit
tried all kinds of it. non worked
i even tried to change transform.Translate to RigidBody.MovePosition
still goes through
can u paste ur full code?
thx.. im dragging it in my project to see if i cant help ya get it working 🙂
thank you so much! i really appreciate it
i have a couple of car controllers on my YT channel w/ collision and a github project with the complete project if u wanna check those out
its a 3d set up tho
rather than a endless runner setup like u have
we'll try to get this to work with physics tho first 👍
yup found your channel
im just hoping it wont get too complicated cuz at the time being im too dumb to understand anything. as i said i just started today
gotcha working 👍
ignore the orange car doing acrobatics in the background
oh ur the guy who made the doom clones! used to watch those before i even started unity and thinking i wanna try that one day
currently watching ur car controller vid
using UnityEngine;
public class PlayerController : MonoBehaviour
{
// Variables
public float speed = 40;
public float speedTurn = 15;
private float leftRightInput;
private float forwardBackwardInput;
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
private void Update()
{
//Input should be called in Update so u get a new input every frame
leftRightInput = Input.GetAxis("Horizontal");
forwardBackwardInput = Input.GetAxis("Vertical");
//rotating or translating the gameObject itself should also be done in update
transform.Rotate(Vector3.up, forwardBackwardInput * speedTurn * leftRightInput * Time.fixedDeltaTime);
}
void FixedUpdate()
{
//anything physics related should be here in the fixedupdate
rb.AddForce(forwardBackwardInput * transform.forward * speed * Time.deltaTime);
}
}```
heres the code i used
just make sure to freeze ur rotation on the x and z
and that'll keep ur car from flipping over
i think that was ur problem originally when u tried to use addforce 👍
exactly! it worked fine with going forward. but backwards it just did a backflip
thank you so much dude!
no problem mate...
u evidently tried before hand to get addforces and stuff to work.. so ur on the right path.. code.. test.. try to fix.. rinse and repeat..
ull be coding up games before u know it 😄
@frosty ore
so i got to another problem. was working on it for a while but couldn't figure it out
so thanks to your help and advice about freezing the rotation on x and z axis, it now moves forward and backward nicely. the thing is with the rotation, is not effecting the path of the car and if you rotate it still goes the global forward and kinda just drifts
im going back to your youtube video for possible clues
whats the cars heirarchy look like?
the red part is the parent (which has the script, collider, and rigid body components) wheels and the top part are attached to the parent
i noticed you made a sphere for the overall function and mesh itself is separated. im trying translate my heirarchy the same way
well ur AddForce function uses transform.forward
the blue arrow is the transforms forward..
i think in ur example ur rotating the car model.. but the rigidbody.. (the main parent) is still facing forward
after u turn the car click the Car parent and see if hte blue arrow is lined up with the car or if its still facing foward down the road
what i do in my script is I rotate the car.. model..
and then when i apply forces to my sphere im not using the spheres forward direction
im using the cars forward direction instead
so is ur rotation function rotating the rb or the car model?
if its rotating the car model where u add forces u can
rb.AddForce(carGameObject.transform.forward * input * moveSpeed);
so it always pushes the force towards the facing direction of the car
im going back to your youtube video for possible clues
i would take this with a grain of salt.. considering my setup is very different..
i unparent the car model from the root car object in my start function.. so in my code i have to set the cars position to match the rigidbody after every time i move it..
and then i move the rigidbody relative to where the car is facing..
i have to unparent it because if it remains a parent i move the sphere and then the car moves too because its a parent.. and then sphere has to move to catch up.. so u get weird rubberbanding and stuff
so the thing is transform.forward didnt worked. the car just wasnt moving so i used new Vector3(0, 0, 600) instead and then it worked. the blue arrow seem to be in the right direction
https://streamable.com/00m664
and also carGameObject.transform.forward dosent seem to be the right syntax. i assume you just said it as an example but im not sure how the syntax can be corrected
yea its just an example
ud need to assign it
public GameObject car;
and then car.transform.forward; would be w/e gameobject u put there
's forward direction
something doesnt seem right tho
working fine in my scene
the car object
just a rigidbody and a box collider
car model is just an empty gameobject w/ a cube as a child
^ a prefab of the car.. u could just add ur graphics to the car model and line it up
if that package doesnt work in ur scene.. make sure ur car isnt a child of something else..
like Environment or something.. it might be messing up the transform.forward..
im not sure why transform.forward havent been working at all. i just have used new Vector3(0, 0, 600) all the time im not sure how to apply it with the GameObject variable
tysm. ill take a look
wtf... i just opened the package in a completely new project and its not working like this at all
it doesn't move. just rotates
same with my project when i use transform.forward
bruh right right sorry
😉
its a balancing act between the forces u use
and how much mass and gravity u have on the rigidbody
Great news! 🙂
i lost a few braincells but boi does it feel good to finally see it working. thanks so much
not a problem..
Is there a way to push an object with a kinematic object? I have my character set to kinematic and want to push a block.
NVM, I'm just dumb. I do have a follow up question though. Should I add the script to do the pushing within my player controller or add it to the actual movable object? Does it matter?
if your player is kinematic, and you want it to push objects, the best way is to move it in FixedUpdate with Rigidbody.MovePosition
The object being pushed needs no script, it just needs to have a dynamic Rigidbody and a collider
Got ya. That seems better for sure. I think I’ll make a state for it, that way I can control the speed when pushing
anybody have a good method for limiting angular rotation on more than the X axis in Unity? configurable joint allows for doing it with X but that's it afaik 😦 I'm thinking of using colliders and layers 🤮
limiting rotation or freezing rotation?
limiting x and z, freezing y.
nvmd, I didn't click the little thing on z limit. My brain thought the thing below showed it was already clicked. Arg.
How can I calculate the impact force of an object with a trigger collider and a rigidbody?
average impact force is F = (0.5f * mass * velocity * velocity) / distance
(0.5 * mass * velocity^2)/collision distance
cool, so what if that distance is 0?
say, the two objects don't deform at all,
or should it just be a very small number?
there is no impact force with a trigger
I am trying to simulate one
infinite force at distance 0
nothing in newtonian physics stops instantly
👍
alright, I suppose I should find a chart of the amount by which different materials deform
because I somehow feel that infinite force wont fit the bill for my purposes
making it physically accurate is probably not necessary. a simple impact model is probably giving good results too.
what do you mean by impact model?
a realistic model would require simulating deformation, which is expensive
agreed, and definitely not something I intend to do
it would make sense to simplify that
alright, I'll try testing it with some generic small values
I have been trying to make universal physics simulation like in KSP and it works fine.
Then I tried to add an orbit like system and I can't understand it and figure out how. Any help?
The orbit system is easier than the air physics imo
Which part do you have trouble with?
the orbit one
i need to use something called initial velocity but i dont understand it
I’m currently using a sphere collider with a torus to make an inner tube going down the slide, but i have to lock the torus’ rotation otherwise it moves unrealistically, but when the rotation is locked it also doesnt move realistically because its supposed to look like a water slide with the inner tube going down instead of just staying in an upright position
I’ve tried making it so that just the torus (inner tube) has proper collision but then its collision causes it to stop sliding prematurely
I’ve tried also using a mesh collider but it doesnt seem to work properly on it
Im thinking i could make it follow a path based on the slide and have it increase in velocity depending on the downwards direction it’s going and decrease in velocity depending on the upwards direction it’s going but im not sure how difficult that’ll be to code
maybe something like this? https://hatebin.com/wzmiilmuok
Not sure if this is an actual physics question, but:
I just added a script to increase gravity at the crest of a jump, but when the character falls from over a certain height, it clips through the ground box collider. Any tips on where to start looking into what's going wrong?
sounds like your run of the mill tunnelling
thank you 🙂
Huh. That seems too simple. I set Rigidbody collision detection to continuous and it works ^^
I have a mesh, but I want to prevent it from falling into the ground..
Here's my mesh with gravity off.
But I want for my mesh to run without falling off the plane.
What components are on your character? How are you moving it? What does your code look like?
Is there any known intros into ballistics? I am trying to simulate player as cannon ball shot, while keeping X axis fully static in 2D. Or maybe I need smth else for that?
why collision2d.relativeVelocity returns zero while one of the collided objects doesn't move and how to fix it?
what is Vector3.Up for 2D space?
I'm trying to make use of LookDirection
rotate my object based on direction vector
it's 0,0,-1f
if anyone curious
i have a rig similar to a ragdoll. But, i'm using 'Configurable Joints'. I'm applying torque force to a joint, how do I make it not effect its connected body as well?
Is there a way to have a collider automatically fit to an object?
not with scripting or during runtime, just in the Unity Editor
Use a Mesh Collider
No it's just Vector2.up
Which is the same as Vector3.up without a z coordinate
oh
I didn't know that was a thing xD
welp
0 0 -1 also works perfectly
and is compatible with math package
Something's weird with your setup if that works for you because that's Vector3.back
true, I think my character is backwards
but that is intended
float2 direction = new float2(horizontal.value, vertical.Linear.y).Normalized();
quaternion newRot = quaternion.LookRotation(new float3(direction.x, direction.y, 0f), new float3(0, 0, -1f));
var rotData = GetComponentDataFromEntity<Rotation>();
rotData[player] = new Rotation { Value = newRot };
thanks
Lets say I have a "powerup" that I want to float up and down. I want gravity to apply to it, so that it doesn't float high in the air, only just above the ground.
How can I give it gravity via rigidbody, with a collider so that it stops at the ground, without the player colliding with the rigidbody?
Layer based collisions, and giving it two colliders:
Powerup
Physical Collider (not a trigger. in a layer that doesn't collide with the player)
Trigger Collider (yes a trigger, in a layer that does collide with the player)
My experiments with vehicle physics: https://www.reddit.com/r/Unity3D/comments/sm4p2l/i_spent_the_last_week_messing_with_vehicle_physics/
@timid dove Forgot to respond earlier, but that was exactly what I needed. Thanks so much! 😄
is there any easy way to make a RigidyBody2D with dynamic simulated physics NOT slide down a slope?
currently my enemies are using RB2D, and they cannot climb even slight inclines, they just slide down
oh actually a physics material with a friction of 1 kinda does the trick
i wasnt sure where to ask this because its about colliders but ill try here:
i have my map that has a mesh collider for the player to walk and etc, and i want to make it so when the bullet hits anywhere on the mesh colilder it will destroy the bullet, but it doesnt work in some places:
on this corner it works:
but on that wall it doesnt:
Make box collider ignore steps mesh collider anyone can help?
Simplest thing is to just use a mesh that's like a flat wedge for your stairs collider instead of a detailed staircase mesh.
Well I know that but i want my character to able to deal with every obstacle that's less than 0.5 hight because at some point of the development I will need that because iam planing to make the game with custom maps so... and I don't think ppl will appreciate a physic game with fake stairs
I dont care how big the solution is I just need it
Basiclly my question is can I disable collision at specefic point on a collider
Not the whole collider
Or ignore it at that point
Guys, need your help!
How do you fix glitching on character movement thru non-flat textures?
Please take a look on short video below. Character experience "blinking" glitch..
You are probably doing something like calling Move twice per frame on a CharacterController
How to verify if? not using Move more than in our "Update" or something?
How many times are you calling Move in Update?
You verify by reading your code
Doing now, but I dont think I ever call it more than in one FixedUpdate
Are you using CharacterController or Rigidbody?
CharContr
Alright so count the times you're calling Move
I have really big "solution" for movement that i did a year ago 🙂 checking that my function to move charcontroller not called more than once. Thanks! will update
I have only one function where .Move is called and 1 reference to it.
So looks like only one Move per frame
Thx m8
That is better video of the issue...
Guys please advise how to fix that?
I'm using CharacterController.Move()
This discord does not have a place for questions like this that are not directly Unity-related.
it's for my unity class
It isn't
it is
it's for ap physics u mech
mechanics for unity
colloquially ap physics c mech
Sure, if you can show your work in Unity, you can get help. Otherwise:
If it's not got Unity in it, it's not directly Unity-related. Seeing as you phrase it as "physics homework", I am inclined to believe you are lying
!mute 722482434154823750 24hr no
the one true god#7771 was muted
hey, why does Unity sometimes ignore collisions with small triggers, if they happen at a fast speed? Any way on how to prevent this from happening? I had an issue like this and fixed it by making my trigger bigger, but still, this is probably not a perfect solution.
This explains everything, thanks a lot
Wait wait wait,
Please tell me you're not using a character controller's .move function in fixedupdate?
Yeah, it is update. Not fixedupdate.
The problem is still present
Oh good - show your movement code.
Give me 30 min. Brb home soon
Also double check your variables on the character controller component.
The skin width should be about 10% of the radius and min move distance should be set to 0. This is not default, but the official docs say it should be 0 in most cases. Why they have the default set to the exact opposite of what they would recommend? I have no idea.
These values work well for me but your character may be bigger/smaller
@nocturne fern My movement code is huge but in fact, I have a function StartMotor() listed in "update"
And start Motor itself contains
_characterController.Move(_playerDirectionWorld * Time.deltaTime);
I also tried values in your examples (i have super similar and tried both). No changes
Well first of all displacement is equal to velocity x time not direction x time. But I'm guessing that's just a misnamed variable.
One line of any code will never really reveal the issue. Like I said check your character controller settings, bad skin width values can cause problems and if minimum move distance is not set to zero it can cause stuttering.
Im literally commented all other lines of code and still happening.
Also trying diff values of charactercontroller. still the same
Is it just the rock mesh that you have trouble with or is this happening often?
all meshes where my slope limit close to the angle I need to move on it
It was a code issue indeed...
My function to apply sliding was glitching 😉
thanks for help anyway!
for my ai instance, the raycast2d does not originate inside the collider that is attached to the child gameobject. it originates insides the parent's collider, how can i make it ignore the parent collider. at the same time, i dont want it to ignore it self, because there are other instances that are clones of this gameobject
The character controller should actually handle sliding for you if you do it properly.
<@&502884371011731486> nitro scam
Hi guys, I have a PID controller to balance a bike but I have problems when its going uphill or downhill, anyone can give me some insight regarding this?
Hmm, Hello everyone, I have this problem that when my object collides with a certain collider instead of inverting its velocity, it decreases the velocity value very little value over time, it works well when colliding for the first time, but when it collides for a second time it encounters the problem I mentioned earlier, any advice for this?
P.S : Sorry for bad english
So in my game, i created a forcefield shader that i applied on a sphere mesh. now i want to use that forcefield as a barrier for my map, like a battle royale damage circle altho with/without collision. how do colliders work with meshes with inverted normals?
like if i have a sphere thats inside out, will it act weird or? i remember having some extremly weird glitches before where my player would shake a lot but it could be unrelated, but i'm still unsure if this is even the right approach
Oh and it's in 3D btw
you can always enable backface
on my inverted sphere or?
then you don't have to invert it
I presume then it should just work
but do you actually want to use it as a collider anyways?
probably just a trigger?
well idk im thinking about that tbh, i think it would be cooler if you slowly died from going out of bounds instead of just getting bounced off by a wall
if it's a sphere it can just be a distance check as well
like from the center?
yeah
hmm that could work too
I think i’ll do a distance check tbh, sounds like the easiest solution. Altho i’m still a bit unsure on how backface culling works so i’ll dig deeper into that though
But thanks for the help!
hope I didn't give too many wrong infos
Hi,
i am having the problem that objects fall through the terrain, once physics applied.
Setup:
- Terrain with Terrain collider
- Stone Object with Mesh Collider and RigidBody
If i click start, the expected behaviour would be that the stone rolls down the mountain on either one side, but what happens is that stone falls through/into the mountain terrain
I'm putting together a first-person character controller. And I must be mixing up local vs global in some way. But I just can't work out what I'm doing wrong. I have head tilt (pitch) and player turn (yaw) all working and camera is hooked up. But when I move forward, the player only moves forward when I'm facing the +'ve z direction. If I turn 90 cw, moving forward moves the player rightward. Here's the code to move the player forward...
// forward
Player.transform.Translate(Player.transform.forward * forwardDelta);
It's like it's applying the transform locally rather than globally - as in, it's applying the vector twice.
So yeah, this works ...
Player.transform.position += Player.transform.forward * forwardDelta;
But isn't that the same as the previous version?
check your layers
Hello, i'm having a problem with 2d colliders. feel free to inform me if this is not the right channel to post about this problem. i'm doing an endless runner minigame right now. i've done everything i know to make the coin pass through-able while destroying it. 80% of the time theres no problems, but sometimes when i jump at it from below it bonks my player character on the head anyway. any advice?
the code on the coin prefab that interacts with the player's player tag
the coin prefab's components
If you want to pass through a collider while also detecting it, you need to turn on IsTrigger on the coin's collider.
thank you, i will try that.
You also need to use the equivalent built in function for it as well
https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
Why when I rotate my boat it goes up like a helicopter
The more I rotate the faster it spins up
in the first video the physics of the swords break and go allot slower when it is published but in the second video in the editor it is working as intended.
Has anyone gotten this problem before, i can't wrap my head around it
maybe you forgot to make some part of it framerate independent
hi im using a basic rigidbody2d and the issue im running into is that occasionaly, the player will land and he'll do a small bounce with no jump input
im not sure how to fix that, if i even can but would be appreciated
Thank you for looking at my problem, can you be a bit more specific maybe, i tried to figure what you mean but wasn't successfull
I have a ball with 1 collider + rb and a cylinder with 1 collider.
Cylinder monitors for OnCollisionEnter and performs the following logic if the colliding object is the ball :
set ball's velocity to zero, add force to ball in direction ball.position - cylinder.position(so away from cylinder)
Somehow, OnCollisionEnter gets called twice occasionally
any gotchas I don't know about?
ok, well apparently setting the velocity to 0 directly was the culprit.
ball.Rigidbody.AddForce(ball.Rigidbody.velocity * -1f, ForceMode.VelocityChange);
works fine
Anyone know how to make chracter controller ignore raycasts
Can anyone help me on the difference of center of mass and center of gravity in Unity? I understand that there's ways to set both in code, but how are either calculated in the first place? Do they relate at all to the objects origin, or the origin of the mesh being used for the collider?
Many tutorials treat them as being the same, but from my understanding they are not, right??
center of gravity and center of mass are the same. by default it's calculated from colliders of object:
If you don't set the center of mass from a script it will be calculated automatically from all colliders attached to the rigidbody
hello, I have a question. is it make any sense? and if yes how much performance I'll get?
Don't crosspost @digital stump
the way I understand it, every OnTrigger call makes more overhead so less would be better. I think the script on car only sounds cleaner even if the performance difference would be negligible
The car should be checking the collision to avoid having potentially hundreds doing it themselves.
I got it. sorry, just didn't know what topic will suit better. I won't do so in the future
about the answer- I forgot to mention that I will be sending Do_Something(Vector3, GameObject, and Float) is it still better to Put a Collision-check on the Car?
Thank you
Yeah, even just because as mentioned above it makes logical sense the car is responsible for this.
The car crashed into the tree, not the other way around.
Cool, i see. THX again
Hi all! I'm having a little strange behavior from Physics.CheckBox where it can detect an object outside its collision scale, and its offset is quite large 😦
idk, what is happening?
all scales are 1
maybe it's debug with wrong scale?
ahm...
now works correctly
I just subtract the scale from it by (1,1,1)
so... does that mean physics.CheckBox by default comes +(1, 1, 1)?
this is kinda confusing...
anyone know how yo use animation rigging for gorilla tag movement?
Hey guys, I added a Physic Material 2D to my tilemap but it doesn't seem to affect my player (who has a dynamic body type). Changing the values of the material at runtime or inbetween doesn't change a thing :/
Okay so PS: Not exaclty. The friction value doesn't seem to change a thing
can anyone share a resource for "swiping touch control for hypercasual games"?
is the collider set to fit the cube?
atleast there's this offset value in physics settings
can i set it compelatly to 0?
it can't be 0 but it can be close (0.0001 seems to be the smallest value). small values can cause some jittering so it would be better to decrease it only the amount you really need
how do i get my fixed joint to not break?
the break force and torque are both infinity
but it still breaks
anyone have any idea as to why I am getting these irregular physics.processing spikes?
Many thanks
Hi guys, I have the following problem, when my player jumps on a slope, it jumps more than in the normal ground.
The code for jumping is
{
isGrounded = false;
rb2D.AddForce(new Vector2(0f, jumpForce));
}```
Is there any way to fix that?
This isn't enough context
I'd guess you're applying the force more than once on the slope
But hard to say without seeing more code
could you be any more broad
well it literally wont tilt to 0 degrees on the z-axis
When it tilts to the left or right, it wont tilt back anymore
its impossible to debug your problem with that information
I would need to see code etc...
there is no way of telling where the problem lies if all I have is a picture of a boat
my code is not preventing it from tilting back
I have a Rigidbody2D that I call MovePosition on in FixedUpdate. This works.
If I parent that RB to a gameObject who's transform.LocalPosition is being set to on Update or FixedUpdate, MovePosition no longer moves the RB.
How can I move the RB respective to its parent, but also still be able to move the RB itself?
Hello everyone.
I am facing this issue in my game:
Whenever the player touches an object that has an animation in the environment, it clips out of the map and falls down..
What did I do wrong? And what should I do to fix it?
im trying to get this "spoon" to be attached to a spinning joing, but when i do it glitches out when the player bumps into it
Is there a preferred method for getting the average of collision contacts? For instance, to spawn a prefab at the averaged position and normal of multiple contacts. Or is there a better approach altogether?
Ok, odd question: let's pretend we have a character with hair at the back of its head, hair that can take the form of strange wings (darker part on sketch, connected to the bottom back of the head).
The hair does not require any energy in this case, and it can be more or less dense.
Can the character possibly fly with this size of wings? If yes, how fast should the wings flap for the character to fly?
Otherwise, how big should the wings be so the wings don't have to flap at a ludicrous speed?
(also check previous, more help-requiring questions)
Depends - does your guy fly like a bumblebee or like a bird?
https://www.livescience.com/33075-how-bees-fly.html
I assume he would fly like a bumblebee, despite the wings possibly disadvantaging him like by blocking his view
(so, the back/front flight motion)
It actually doesn't seem specific to bumblebees, even less if you include fictional characters yet the flight may get mixed with bird flight and/or the the characters can also glide.
any tip what I could possibly miss when setting up collision detection?
my OnCollisionEnter2D is not getting called
it won't work for a kinematic body
only works with dynamic bodies
any way to at least call check myself?
Hey,
so i played SpaceFlight Simulator an my Mobile and im trying to recreate the Planet Orbits (Gravity). I tried with Newtons Law but it doesn´t seem to Work quire right. I gave every Physic Object a Script so they attract each other based on the Mass. Does anyone have a better Solution? I would Love to be able to launch e.g a Rocket from the Planet 😄
I recommend this video for inspiration/code tips on such a system https://www.youtube.com/watch?v=7axImc1sxa0
I haven't played the game you're talking about though so I'm not 100% sure it's what you're looking for.
Oh sorry i forgot to link the Game or any Footage and i already watched Sebastian Leagues Video 😄
Heres the Steam Trailer (https://youtu.be/mULNAzzZ14Y)
Wishlist us on steam to get notified on development updates!
https://store.steampowered.com/app/1718870/Spaceflight_Simulator
My Problem is that the Planets are moving to Objects with very little Mass too but they should stay in there Orbit around for example a Star and that when a Object is to Close to the Ground its getting Stuck inside the Planet
I mean it just sounds like you're complaining that your physics are too realistic?
Hi people, anyone knows about Cloth in Unity? I have a character with a cloth hanging from his belt, is it strictly necessary that the mesh of that cloth be separated from the mesh of the character?
Is there a way to run collision check myself? Basically I simply want to have collider only, without any rigid bodies
and on demand I want to see whether that collider collides
There are direct physics queries you can use on demand such as Physics.OverlapBox
Feel free to browse the scripting reference to see all of them
you mean do collider casts?
not really what I want
but I guess physics don't work that way
I mean any of those various direct physics queries, including but limited to xxxCasts
Good evening guys.
I have tried to find the solution online but couldn't find an answer. I'm trying to create an icy ground but can't seem to make it work. My character is simply ignoring the friction (bouciness works). I gather it is because my player movement is dependant on the renewal of the velocity each frame but I'm lost on how I could fix that. Simulate fricition with the gorund ?
{
dirX = Input.GetAxisRaw("Horizontal");
if (dirX < 0 && (speed > -maxSpeed))
{
if (rb.velocity.x <= 0)
{
speed -= acceleration * Time.deltaTime;
}
else if (rb.velocity.x > 0)
{
speed -= 2 * deceleration * Time.deltaTime;
}
}
else if (dirX > 0 && (speed < maxSpeed))
{
if (rb.velocity.x >= 0)
{
speed += acceleration * Time.deltaTime;
}
else if (rb.velocity.x < 0)
{
speed += 2 * deceleration * Time.deltaTime;
}
}
if (rb.velocity.x > deceleration * Time.deltaTime)
{
speed -= deceleration * Time.deltaTime;
}
else if (rb.velocity.x < -deceleration * Time.deltaTime)
{
speed += deceleration * Time.deltaTime;
}
else
{
speed = 0;
}
rb.velocity = new Vector2(speed, rb.velocity.y);
}```
The part of my script controlling horizontal movement
this all seems like an overcomplex version of:
void FixedUpdate() {
float hInput = Input.GetAxisRaw("Horizontal");
rb.AddForce(new Vector2(hInput * acceleration, 0));
rb.velocity = Vector2.ClampMagnitude(rb.velocity, maxSpeed);
}``` and just set some drag on the Rigidbody or use friction on PhysicMaterial2Ds for the slowdown part.
I can't seem to get the DOTS physics package to work, I'm getting errors at Broadphase.cs:873, Is there a specific Unity version I should be using? I'm using the latest LTS
#archived-dots might be a better place to ask
It's moving
please help, I don't know why why transform is not locking to its child objects
the child object positions is 0,0,0 to its parent, but when I move the parent position, the child gets separated to its parent origin
Because you have your tool handle position set to Center instead of Pivot
both of these objects have a collider but they wont collide. can someone help?
show rigid body
i already got help thanks anyways
Irrelevant question:
Is there a way to get collision info in Trigger collision in 2D?
Basically I need to get at what angle collision happened and on what distance.
OnTriggerEnter2D(Collider2D collision)
Only provides collider
yep
RaycastHit2D[] results = new RaycastHit2D[1];
collision.Cast(playerController.PlayerVelocity, results, 0.1f);
I guess I need to make my own new cast
sad life
Sooo, my 2D sprite is constantly rotating in update to look at where character is going.
I want to add flip annimation (360 angle flip) on Z axis, but with respect to that look rotation.
Basically character does flip, but at the end of animation he will naturally slowly get to his look current look rotation.
private async UniTaskVoid FlipAsync(float duration, CancellationToken cancellationToken)
{
shouldRotate = false;
var endTime = Time.time + duration;
var angleDelta = 360f / duration;
float angle = transform.rotation.eulerAngles.z;
float time = 1f / duration;
float counter = 0f;
while (Time.time < endTime)
{
counter += Time.deltaTime;
Quaternion targetAngle = (counter * time < 0.75f) ? Quaternion.Euler(0f, 0f, angle) : VelocityRotation;
transform.rotation = Quaternion.Lerp(transform.rotation, targetAngle, Time.deltaTime * 5f);
angle -= angleDelta * Time.deltaTime;
await UniTask.Yield(cancellationToken);
}
shouldRotate = true;
}
I came up with this little part, but it doesn't respect current rotation (VelocityRotation) enough. So after animation is over by 75% it starts lerping towards that look rotation, but since that swap is instant - animation feels unnatural.
Any tips how I can smooth it along whole animation cycle?
And that "constant" rotation I mentioned earlied is disabled by shouldRotate
I think you might wanna use Quaternioun.MoveTowards?
or make your lerp interval (Time.time-startTime) / (endTime-startTime)
instead of Time.deltaTime*5f
I don't have transforms to move into
and creating them is just next level complexicty
@wispy tinsel So you have a character
In a top down game
Probably looks at the mouse position
So its not top down?
no
Okay
damn, should have mentioned it
If your characters forward is the look direction, I'd have easy time explaining a solution with quaternion.lookdirection and quaternioun multiolication
Quaternioun.Euler(0,0,interval * 360) * Quaternioun.LookRotation(velocity)
?
wanna do something like this?
thats flipping
flipping with respect to look
while also doing 360 flip
ah but velocity also changes alot
yeah
and thats the problem
so initial rotation won't be equal to end rotation
and that my first code shows it in it's glory
rotation gets big spike at the end
so I think I need either figure out
how to change deltaAngle over time
which is target angle basically
why does flipping needs to depend on velocity?
then the problem is just recovery from flip okay
rotation = quaternioun.slerp(rotation, quaternioun.lookrotation(vec), deltaTime * 5)
and whats the matter with this?
so the only good fix to this would be making flip smooth so it's end position would be that look direction
well matter with this is that after 75% when instead of my 360 rotation I start to lerp to velocity rotation
which is supposed to be recovery
it's just bad
because velocity rotation can be very different
and thus if it's too big -> lerping through it is way faster than initial flip lerping
so you wanna continue the flip rotation until it meets the velocity rotation and then you wanna stop the rotation?
@wispy tinsel
kinda, but it needs to be in fixed time as well
so whole flip takes 2 second, neither less nor more
var endTime = Time.time + duration;
var angleDelta = 360f / duration;
float angle = transform.rotation.eulerAngles.z;
float time = 1f / duration;
float counter = 0f;
while (Time.time < endTime)
{
counter += Time.deltaTime;
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0f, 0f, angle), Time.deltaTime * 5f);
float curAngle = transform.rotation.eulerAngles.z;
if (-10f <= curAngle && curAngle <= 10f)
{
break;
}
angle -= angleDelta * Time.deltaTime;
await UniTask.Yield(cancellationToken);
}
here's my best take on it
could check the difference between rotations and its below some value, you can do the lerping
once I reach Identity rotation I just break lerping, but it's not doing fixed time
so it just recovers itself, which makes it somewhat smooth
but still can be glitched if current velocity looks almost at floor (0,-1,0)
your flip needs to ends in 2 seconds huh
it's just example, obviously I'll play with values
i mean a fixed duration