#⚛️┃physics
1 messages · Page 52 of 1
so I iterate through all possible points
that's a differently problem i think
i think there's a voronoi shatter plugin
you're looking for an effect called a voronoi shatter
yes, but people will have only written a high performance shatter for voronoi 🙂
i would start by looking at that, and then just making the adjustment you need
For more details and source code, see: https://github.com/OskarSigvardsson/unity-delaunay
it shatters in different pieces, not cubes
thats what im talking about
I wanna make it like this
In this video we will destroy cube into pieces and give it an explosion effect. We will use OnTriggerEnter, CreatePrimitive and AddExplosionForce.
Download Script:
https://drive.google.com/open?id=1ZpTd38h2zi8Td5Rj6a70PiPcfOwJPe6s
but its only applicable for the Cube
so I basically need to see if any given point is inside a mesh, and if it is - create a voxel there
i just need a function that will return true or false and take Vector3 as an argument
where Vector3 is the point we're testing
Here is the iteration method
public void Recreate()
{
float voxelSize = 0.1f;
var collider = gameObject.GetComponent<MeshCollider>();
float height = (float)Math.Round(collider.bounds.size.y, 2);
float width = (float)Math.Round(collider.bounds.size.x, 2);
var startPoint = collider.bounds.min + new Vector3(voxelSize / 2, voxelSize / 2, voxelSize / 2);
var direction = Vector3.forward;
for (float z = 0; z < width; z += voxelSize)
{
for (float x = 0; x < width; x += voxelSize)
{
for (float y = 0; y < height; y += voxelSize)
{
var testPoint = startPoint + new Vector3(x, y, z);
/// PSEUDO
///
/*
if (testPoint.isInsideMesh)
{
Instantiate(voxel, testPoint, Quaternion.identity, parent.transform)
}
*/
}
}
}
}
Iteration itself works correctly when instantiating small cubes in each iterated point
If you have predictable voxel shape it becomes trivial to figure out that with math.
Other way you can do that is just split vertices of the shape into plane shapes, from there you can split them into squares and create voxels when they correspond with squares on the next level
Testing point inside simple geometric shape is much easier
I tried to avoid messing with vertices and all this complicated (for me at least) geometry stuff, but looks like there is no other way for me
thought something like CheckSphere would work when completely inside a meshcollider
i think you've figured it out
if the meshes are not dynamic, you can calculate ahead of time
navmesh and the lightning system both have features that require voxelizing geometry and spaces (negative and positive)
will give it a shot, thanks
if you want to hijack a technology those two may haev something you could use
I did it!
Extremely messy but it works
Here's the code in case someone wants to improve it or just grab it
public bool CheckInside(Vector3 point)
{
Physics.queriesHitBackfaces = true;
var ups = Physics.RaycastAll(point, Vector3.up, Mathf.Infinity);
var fronts = Physics.RaycastAll(point, Vector3.forward, Mathf.Infinity);
var rights = Physics.RaycastAll(point, Vector3.right, Mathf.Infinity);
var downs = Physics.RaycastAll(point, Vector3.down, Mathf.Infinity);
var backs = Physics.RaycastAll(point, Vector3.back, Mathf.Infinity);
var lefts = Physics.RaycastAll(point, Vector3.left, Mathf.Infinity);
Physics.queriesHitBackfaces = false;
if (ups.Length > 0 && fronts.Length > 0 && rights.Length > 0 && downs.Length > 0 && backs.Length > 0 && lefts.Length > 0)
return true;
return false;
}
Full script with iteration. Should work for any MagicaVoxel model
"Extremely messy but it works" That's most of the games out there. Congrats 😄
"If it works - don't touch it" --Socrates
And that includes AAA as well
Is there a way to improve it?
With pure math it could be much neater, faster.
Actually, you would want to use this version instead to not create garbage https://docs.unity3d.com/ScriptReference/Physics.RaycastNonAlloc.html
Cool, thanks
Just noticed it could miss some small features 😦 but still ok, I guess
awesome!
TY 🙂
hello! I'm having a problem with my physics materials. I have an object which I want to have no friction, and slow it down with a different script. I had this set up for months, and it's been fine. But now it's giving me an issue, where it seems like it has high friction, until i change the value on the file? gif attached to show what I mean
Improved a bit. Instead of casting infinite rays that will hit other objects I limit them to collider bounding box
float height = (float)Math.Round(meshCollider.bounds.size.y, 2);
float width = (float)Math.Round(meshCollider.bounds.size.x, 2);
public bool CheckInside(Vector3 point, Vector3 startPoint)
{
//startPoint = meshCollider.bounds.min
Physics.queriesHitBackfaces = true;
float rayThreshold = 0.01f;
float deltaX, deltaY, deltaZ;
deltaX = (float)Math.Round(point.x - startPoint.x, 2);
deltaY = (float)Math.Round(point.y - startPoint.y, 2);
deltaZ = (float)Math.Round(point.z - startPoint.z, 2);
var ups = Physics.RaycastAll(point, Vector3.up, height - deltaY + rayThreshold);
var fronts = Physics.RaycastAll(point, Vector3.forward, width - deltaZ + rayThreshold);
var rights = Physics.RaycastAll(point, Vector3.right, width - deltaX + rayThreshold);
var downs = Physics.RaycastAll(point, Vector3.down, height - (height - deltaY) + rayThreshold);
var backs = Physics.RaycastAll(point, Vector3.back, width - (width - deltaZ) + rayThreshold);
var lefts = Physics.RaycastAll(point, Vector3.left, width - (width - deltaX) + rayThreshold);
Physics.queriesHitBackfaces = false;
if (ups.Length > 0 && fronts.Length > 0 && rights.Length > 0 && downs.Length > 0 && backs.Length > 0 && lefts.Length > 0)
return true;
return false;
}
so i'm in a position where
i need to be constantly updating the rigidbody velocity myself
but i also need to be updating the object's transform
any way to make this all play along well without any jittering ?
managed to fix it i think -- i ended up updating rigidbody.position
and the jittering seemed to be because I was using transform.InverseTransformPoint(rigidbody.position
wanted to do the calculations in local space
however i think since transform was lagging behind a frame the inverse position was wrong
i switched to doing worldspace and it turns out fine
any idea if i could still do it in local space without jitter?
nevermind -- still got jitter
does Overwatch engine have to use constant tick rate for physics or is it internally flexible?
in other words, - if the tick-rate slows down, does the game slow down as well?
im gonna leave some details here, in case anyone can help shed some light for me:
// Called if I am grounded, from within FixedUpdate
// Distance is the distance of the target point from the ground position (obtained via raycast)
if (!Mathf.Approximately(distance, _groundOffset))
ApplyPositionSpring(distance);
...
private void ApplyPositionSpring(float currentDistance)
{
var pos = transform.InverseTransformPoint(transform.position);
var target = pos.y + (_groundOffset - currentDistance);
var time = _slope < 0f ? _stats.UpSpringSmoothTime : _stats.DownSpringSmoothTime;
pos.y = Mathf.SmoothDamp(pos.y, target, ref _springVel, time);
transform.position = transform.TransformPoint(pos);
}
this is to keep an object off the ground a certain distance away from the ground position
the objects velocity is also set from fixed update (after this call occurs) and I update the rigidbody velocity directly in that function.
the issue is that jitter is caused due to the ApplyPositionSpring function
How can I make a rigidbody always bounce back up to the height where it was dropped from?
so that it can stay bouncing forever
btw regarding my issue: i managed to apparently fix it disabling rigidbody interpolation, and resorting to using a constant time for my SmoothDamp
do ya reckon the smoothdamp issue is bc i am using one velocity for both spring times?
i also decreased the physics timestep to 60fps (0.01666)
but the smoothdamp seems to be the main culprit, and the interpolation was spazzing out probably because of unexpected transform changes
@stable fog i think you could try playing with physics materials on both the body and the surface
Trying my luck here as well, anyone could see the problem in this code? I'm not reaching the inner CastCollider, even thought I'm even now for debug purposes directly fetching the colliders from the trigger event and casting them?
https://pastebin.com/wFNKLiYn
Answer: my input is in world space while it should be in collider space.
Hey guys. I've got a weird issue. I've got a player with a rigidbody that I'm applying my own gravity to, with gravity turned off. For now I'm just pulling them directly down but for some reason my character, after jumping, starts moving sideways.
If I disable my rotation lock you see that the character is trying to fall over, so I'm thinking it's something to do with that which is then translating into movement..
Wait, is it simply because the capsule collider is rounded at the bottom so it's trying to push down and move? ...
Nope. Same issue with a box collider.
How can I increase a rigidbody's terminal velocity?
How could I fix this issue please? I could reduce the character controller's size but then the hitbox would be smaller than the model
change the position of the collider
but then it gets too small and things like this happen
then what is it that you want?
change the position/size of the collider until it encompasses your whole model
I'd like it to be the size of the model but not so that it hangs to platforms like the 1st image
Maybe it's not possible with the character controller
those are two separate issues
depends what you mean by "it hangs to platforms"
resizing the collider is the solution to the problem where the whole model is in the bottom hemisphere
well that it looks anormal and floats in the air
i have no idea what's normal for you
that doesnt look like floating in the air
it looks like he's on the ground trying to eat that platform
hi, i'm trying to work with wheel colliders, and I was wondering if there was a way to control the wheels by velocity rather than acceleration?
write an API that does the math and translates velocity to acceleration 😛
Quick question, what is the best method for a permanent pivot point? I tried attaching my object to a parent empty with a kinematic rigid body, I tried a bunch of combinations with colliders and rigid bodies and messing with the settings, but I need something stronger. I basically want to tether two objects together with a rope and make them impossible to detach
@cloud sphinx maybe joints can help you
I am really confused. My addforce code only works when the "Scene View" tab is attached to the editor, but when I drag the tab to my second monitor, AddForce just stops working. Why is this?
does unity rely on the scene view for physics?
Hello guys ! I have a question.
I created an avatar and added cloth physics on it, I was wondering if there was a way to make the cloth collide with the mesh instead of creating a lot of capsule colliders ?
I have seen mesh collider but I don't think it is what i'm searching for.
Thanks for the help 😄
@sacred briar i think itd be best to use one or few capsules to do that
mesh collider wont update with animation unless you do it yourself
which would be very slow i think
capsules/spheres that best approximate the character shape would work well
@lime knot can u show the current setup
sure
of your player, and your other object
so rn the player'
falls thru the ship?
can you select the ship object in your inspector, show me that
sure
did u add the collider ?
yep
i imported the 3d game kit which said it might change some settings
idk if that is why
can u check the convex option
can u show me the setup of your player object
i dont think a mesh collider works too well for objects with holes
thing is
i made a cube earlier
i still fell trhoug that
even though it had a box collider
a box collider means your player would be inside the box
wat
you need a box collider for the floor and walls
ah
or a mesh collider would work for a cube
the specific shape youre using is probably the reason
use a composite collider composed of several box colliders forming the outside of your donut
hello, I tried the https://docs.unity3d.com/Manual/WheelColliderTutorial.html but the car jumps off anything it touches and at the same time glitches through things, what's going on :/
vehicle physics are one of the hardest things to get right
Hello everyone. I have a FirstPersonController which doesnt move with my boat. I think it's a problem with the CharacterController. How can I fix this?
ur gonna have a bad time
if you want to see it working, check out the car examples here:
http://angryarugula.com/unity/teaching/Physics/
the issue I had was it was totally broken, your example even with reset wheel collider settings (after unpacking prefab) still works just fine on the same terrain my other one just falls through and bounces off... O.o
I disabled scripts on both, reset wheel collider on both, parented them exactly the same, same rigidbody settings... and they act totally different 😦
would it be better to use a configurable joint for suspension and drive? 😆
the more physical components you use the more complex it will be. The best is to directly represent a real physical car but that uses so many physical components it's almost impossible to simulate (in unity at least).
The key is getting the behavior you desire through creative means.
- building your environment in a way that lets you make a simpler vehicle
- fake the behavior without physics
- etc...
my player sprite starts to drife after coming in contact with a collider on my map (2d) any help?
Hey, so this question is a little more general rather related to unity
How do collision systems function are they just simply checking the distance between two objects and checking if it is less than both objects width combined or is there more to it?
Sorry if this is a stupid question
https://stackoverflow.com/questions/22512319/what-is-aabb-collision-detection
is used for most volumetric collision detection. not sure about spheres and meshes tho
Thank you @foggy rapids
Hey I'm trying to understand Physics.CapsuleCast - does the maxDistance parameter really work like the Physics.Raycast maxDistance? I feel like it doesn't - when I have the maxDistance casting from a specific point, I get a much larger distance than expected...
Like, does the max Distance kinda dictate where the collider casts from?
is there a way to slow down physics (slo-mo style) without slowing down everything else? i used Time.timeScale, but the problem is that it also slows down the playback on a Timeline that i'm using and I need the Timeline to play regular speed!
hehe never mind just found the "unscaled game time" option for Timeline's update method
@craggy grove the shape casts cast their respective shape so
there might be a difference yes
how big of a difference are we talking?
Seems to be 5 meters or less... but kinda irritating. I'm trying to find something that would fit the width of a wide line that's rendered by a line renderer
For collisions
Here uploading screenshot
So I'm trying to get the thick invisible line (outlined in the dark blue border box) to create small line renderer "branches" that touch other cars in the thick line's vicinity. The idea is that, when the line or "laser" is small coming from the large vehicle, the line is pretty high since it comes from the middle of this large truck, so we want to make some smaller damaging hits, if you will, within a close radius of the smaller lasers as well
But problem is, as you can see, the cars are not in the range of that invisible line, YET there are small laser branches spawning to reach them
hmm i see
how are you calling the capsule cast btw
keep in mind
the positions you provide are the center of the capsule
Here's more of the expected behavior - the capsule cast has reached the cars
*sphere
can i see your capsulecast call?
have u tried settings the start center and the end center to the same value?
LineRenderer childTriggerLazor = lazer.transform.GetChild(0).GetComponent<LineRenderer>();
float capsuleTriggerLength = (childTriggerLazor.transform.TransformPoint(childTriggerLazor.GetPosition(2)) - childTriggerLazor.transform.TransformPoint(childTriggerLazor.GetPosition(0))).magnitude;
Debug.Log("Capsule length is " + capsuleTriggerLength + " and line length is " + lineLength);
RaycastHit[] childTriggerHits = Physics.CapsuleCastAll(childTriggerLazor.transform.TransformPoint(childTriggerLazor.GetPosition(0)), childTriggerLazor.transform.TransformPoint(childTriggerLazor.GetPosition(2)), childTriggerLazor.startWidth-2, transform.root.transform.forward, capsuleTriggerLength/2, -1, QueryTriggerInteraction.Ignore);
Debug.DrawLine(childTriggerLazor.transform.TransformPoint(childTriggerLazor.GetPosition(0)), childTriggerLazor.transform.TransformPoint(childTriggerLazor.GetPosition(2)), Color.red);
if (childTriggerHits.Length > 0)
{
Debug.Log("Can confirm branch trigger hits");
foreach(RaycastHit hit in childTriggerHits)
{
Debug.Log("Checking hit for " + hit.transform.root.gameObject.name);```
so basically spherecast then
hmm so the positions
can u show me where those two positions might be?
in the scene
Sure
the input positions of the capsulecast
hmm might i suggest a small change that might help?
the capsulecasts maxdistance might be from either of the points -- i cant seem to find in docs which point, or if its a center
could you perhaps try using
a spherecastall instead
since your capsule moves straight forward anyways, its basically a spherecast
I didn't think it was a spherecast... but, maybe that's right
would be easier to find if its a bug or not that way
Wouldn't have occurred to me lol
I'd think there'd just be one sphere that's increasing in radius
it doesn't need to increase either
since your capsule is two spheres of equal length
*radius
casting that would be
the same as one sphere
capsule comes into play when u wanna for example horizontally raycast a capsule
So I'd be able to capture things in between two said spehere?
Well ya I do want to horizontally raycast
It's basically meant to be a super wide trigger laser
then you could simply arrange your points that way
get it?
instead of the capsule facing the truck
the capsule could be perpendicular
from the center
i think i should illustrate
to explain a bit better
Sure
sec
OK
lol it's fine
think of the black boxes as ur truck
first one is the capsulecast u are doing now
the green is the shape being cast
grey is the overall cast path
red is trajectory
second truck is one spherecast
its basically functionally the same as ur original capsule cast
the third one is what i meant by horizontal cast
and its a capsule cast
so i was asking u to perhaps try with a spherecastall
and see if it meets your needs
since a sphere is easier to position and handle the maximum travel distance
i think the bug is coming from the max distance being calculated for the capsulecast differently
also to debug you can
draw a shape in your origin position
draw a ray of distance maxdistance towards the direction
and if theres a hit draw the shape at the hit distance
i do that myself a lot
I suppose I could try that, yea
concerning wheelcolliders, is there a way to get the true current rotation of the wheel?
of course i could have a variable and add wheel.rpm*Time.deltaTime, but I wondering if there was a way to get the current angular position of the wheel errorlessly
Hey all, I'm following the Brakeys tutorial on FPS movement.
But I found that I am colliding with the PostProcessing volume near the middle of my scene.
Let's see how to get an FPS Character Controller up and running in no time!
REGISTER with APPTUTTI: https://www.apptutti.com/partners/registration.php?utm_source=brackeys&utm_medium=social&utm_campaign=brackeyssponsor1
LEARN MORE: https://www.apptutti.com/corporate/?utm_sour...
IT is not on the same layer as my Ground objects so I'm a bit confused. :/
Seems I needed to set the Collider on the PostProcess to (isTrigger)
concerning wheelcolliders, is there a way to get the true current rotation of the wheel?
@proper urchin in the example linked by someone else they use:cs Vector3 pos; Quaternion rot; Collider.GetWorldPose(out pos, out rot)
does anyone here know about car tire physics?
i've experimented with a custom wheel collider for a while, but got stuck months ago and now decided to pick it up again
if anyone is familiar with the pacejka friction formula, i'd appreciate your help
How can I increase an object's terminal velocity? (on the xz plane)
Even when I set an object's mass to 0, it still falls. Why?
Hi is there anyway that i can detect raycast hit which isn't in my layermask?
having a bit of trouble with jumping
when i'm not moving, my character jumps the normal height
but when i'm moving the jump height gets tripled
void Update() {
direction = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
isGrounded = Physics2D.OverlapArea (new Vector2(transform.position.x - 0.5f, transform.position.y - 0.5f),
new Vector2(transform.position.x + 0.5f, transform.position.y + 0.5f), groundLayer);
}
void moveCharacter(float horizontal) {
rb.AddForce(Vector2.right * horizontal * moveSpeed);
if (isGrounded) {
animator.Play("runState");
}
if ((horizontal > 0 && !facingRight) || (horizontal < 0 && facingRight)) {
Flip();
}
if (Mathf.Abs(rb.velocity.x) > maxSpeed) {
rb.velocity = new Vector2(Mathf.Sign(rb.velocity.x) * maxSpeed, rb.velocity.y);
}
}
void modifyPhysics() {
bool changingDirections = (direction.x > 0 && rb.velocity.x < 0) || (direction.x < 0 && rb.velocity.x > 0);
if (Mathf.Abs(direction.x) < 0.4f || changingDirections)
{
rb.drag = linearDrag;
}
else
{
rb.drag = 0f;
}
}
void Flip() {
facingRight = !facingRight;
transform.rotation = Quaternion.Euler(0, facingRight ? 0 : 180, 0);
}
}
here's the code
i can't really pinpoint whats making it do this
am I blind or did you not post the jumping code? 😛
Hey I need to create a semisolid cream like physics. Like how toothpastes come out of the tubes.
sorry friend, i literally have not ever heard or seen that question asked
toothpaste physics
perhaps what u need is
soft body physics
fluid physics?
idk what it's exactly called
probably fluid physics, what ur looking for
my bad here's the updated version with the jumping code
void FixedUpdate() {
moveCharacter(direction.x);
modifyPhysics();
//Jump
if (Input.GetKey("space") && isGrounded) {
rb.velocity = new Vector2(rb.velocity.x, 15);
//Reference the animator tool
animator.Play("jumpState");
}
}
void Update() {
direction = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
isGrounded = Physics2D.OverlapArea (new Vector2(transform.position.x - 0.5f, transform.position.y - 0.5f),
new Vector2(transform.position.x + 0.5f, transform.position.y + 0.5f), groundLayer);
}
void moveCharacter(float horizontal) {
rb.AddForce(Vector2.right * horizontal * moveSpeed);
if (isGrounded) {
animator.Play("runState");
}
if ((horizontal > 0 && !facingRight) || (horizontal < 0 && facingRight)) {
Flip();
}
if (Mathf.Abs(rb.velocity.x) > maxSpeed) {
rb.velocity = new Vector2(Mathf.Sign(rb.velocity.x) * maxSpeed, rb.velocity.y);
}
}
void modifyPhysics() {
bool changingDirections = (direction.x > 0 && rb.velocity.x < 0) || (direction.x < 0 && rb.velocity.x > 0);
if (Mathf.Abs(direction.x) < 0.4f || changingDirections)
{
rb.drag = linearDrag;
}
else
{
rb.drag = 0f;
}
}
void Flip() {
facingRight = !facingRight;
transform.rotation = Quaternion.Euler(0, facingRight ? 0 : 180, 0);
}
}
@willow vortex
hey people, how can I tell my collider not to collide with a specific thing
let's say, with a character controller's collider
@undone kiln set them on layers that are set to not collide, OR if you really need two specific colliders to ignore collision you can use Physics.IgnoreCollision https://docs.unity3d.com/ScriptReference/Physics.IgnoreCollision.html
Hey everyone, I'm trying to make a game and I need a 2d object to not move past a border. However I can't use a rigidbody in this case because it provides all those physics I don't need. How can I accomplish this?
@undone kiln hey, you can use either Physics.IgnoreCollision or you can modify your collision matrix in project settings to choose which layers can collide with the player collider
my RaycastHit cannot detect moving objects though it detects the static ones. help please
@subtle frost Raycast wont detect backfaces by default
Are you perhaps starting the ray within an object?
I added box collider to the moving objects and it works now. But I don't get why, some of the static objects get detected even without it.
i THINK you do it like this:
@undone lynx Thanks for your answer but i shouldn't have changed the layermask. But no matter i will find another solution.
I've got a little ragdoll dude who works just fine. But, when I add an explosion force to him with rigidbody.AddExplosionForce, he absolutely turns to spaghetti. Like he gets all stretched out and his limbs fly everywhere before coming back together normally. Any idea why this is happening?
any way to reduce the ground magnetism that WheelCollider has?
Hello, so I am trying to get my Player to collide with a Capture point
The easy way to do it is with a rigidbody
But I don't want my objects to have physics.
I tried RayCasting, I am pretty sure I did it wrong so I am looking for maybe a more easy solution.
Also yes I know my player model looks great
Actually wait nevermind I think I figured it out
I've got a problem where I had the gravity level perfect, then I moved the rigidbody component above a script in the inspector to tidy up and the gravity now acts much lower. The problem is, I can't add more gravity or addforce won't work because the player is being pushed into the ground to hard. How do I fix this?
It's like the physic's engine has reset but kept certain value or something
I would appreciate an answer because it's kinda stuffing up my entire project
Hi, How could I change the velocity of a rigidbody using an Animationcurve ?
A distance/velocity curve
my 500kg trailer is pushing the rear 4 wheels with 30k spring/10k damping into the ground, what gives ? :/ the truck is 2000kg and works fine on its own
😒
?!
great, seems to have nothing to do with the constraint, the trailer here just sits on its own wheels being pulled by script forces to follow the truck, but whenever it's above the truck wheels they just glitch out and fall into the map 😐
yep, it's simply because the box collider is above it ¯_(ツ)_/¯
When I turn around sharply, the ball turns not directly behind it, but curves around
I'm just using Unity's premade rollerball asset
rb.AddTorque(new Vector3(moveDirection.z, 0, -moveDirection.x)*realMovePower);
move = (v*camForward + h*cam.right).normalized;```
All other movement works perfectly fine, but this doesn't
help?
Are you using wheel colliders or raycasts for the tire physics @willow vortex
@fierce phoenix wheel colliders, why? I mentioned the cause of my issue xD
Hello does anyone know how to magnetise an object to something like a race track? Clearly i am doing something wrong here
exactly
So 2 constant forces pulling it up and down?
it would have to be a balance and have trigger areas
and dampening so it doesnt just bounce lol
ive tried somthing similar in lumberyard but the physics are not so good in that
how to do you dampen it?
duno yet only just started learning unity engine today
well it has promise
I have an issue with my character controller, it sometimes lands on surfaces it shouldn't be able to land on, like very steep slopes etc (even though my max slope is 45 deg). And they don't fall off the steep slopes either, they just stay there and the controller can jump again
is there any guides for better character controllers?
@willow vortex I was wondering if the wheel raycasts were detecting the box above and deciding that the suspension was fully compressed.
yeah probably for either of them, I likely need to disable collision between those things; but I dunno why the visual wheels don't show as compressed in that case...
hey guys Im trying to get procedural animations done in unity and am struggling a lot. can anyone help or point me in the right direction
@willow vortex i think the wheels have a max travel, so they are popping to "max compression"?
@stuck bay get some free ik script and figure out ik target positions
you'll most likely be wanting to do the "figuring out ik target positions" in a coroutine
.
Can also use the animator's animation state scripts
To have it work nice and clean with the animator
That's what i'll try next if i get to doing some animation again
Hi, sorry, but how do I connect my particle effects to my 2D collectable? I've been trying all day, but no dice.
@placid sail can you share what you have so far? in terms of hierarchy
Nvm, fixed it. XD
It seems like changing the mass of a rigidbody completely doesn't affect how fast it falls
ok, it's drag, i forgot
why id unity ignoring offset with collision meshes
Question.
Does anyone else have issues with default character controller and know how to solve it? https://gamedev.stackexchange.com/questions/183408/how-to-improve-the-charactercontroller-for-jumping
on wheelcollider again, it seems that any brake torque above 0 results in locking wheels upon braking... and doing ABS-style of braking makes it brake slower, apparently in nvidiaverse tire slip is more effective braking 😆
Would raycasts be a reasonable way of doing collision detection?
I am currently using OverlapBoxAll, which I suspect might be a bit slow
you can also have colliders with "IsTrigger" enabled to act as an area sensor
Would that be optimal for character movement @willow vortex ?
is there a discord for PuppetMaster?
Anyone know how AI Navmeshagents deal with physics/what takes precedence between a navmeshagent and a rigidbody in terms of moving the object?
Would ideally love to set my AI truck to be moved purely by physics when a force "hits" it, but wondering if there's a cleaner way to do it than having to hard disable the navmeshagent or manually tell it that it just got hit by an explosion from the explosive creator.
@young saffron if the object, has a non kinematoc rigidbody, it will be affected by physics during the physics simulation, while the navmeshAgent will be moving it at it's own update, so you should disable one when you want the other to take precedence.
Ezpz OnColliderEnter call an event that would disable /stop movement from the navmeshAgent for some time.
Does anyone know how I can improve this code so that it only uses one Raycast and then checks from there?
https://hastebin.com/luzayoyoye.cpp
It recognized it as C++
use RayCastAll with no layermask to get an array of RayCastHit. iterate through those looking for the targets you're interested in
Has anyone seen a large spike issue with spawning a few rigidbodies less then 100, unity physx.pxscontact.contactmanagerdiscreteupdate spike in profiler.
seems related to this https://issuetracker.unity3d.com/issues/physx-physx-dot-pxscontext-dot-contactmanagerdiscreteupdate-spikes-when-small-amount-of-rigidbodies-are-being-spawned and found someone talking about something similar related to not having vsync off. Tried that and did seem to "fix" it. Testing build to see if this is just an editor thing
To reproduce: 1. Open attached project 2. Press play and go to profiler 3. In the game press Respawn button 4. In the profiler check...
it has to check for collision after spawning to see if it spawned inside a collider.
Use an object pool
hmm gotcha @foggy rapids usually do but had not wired that up yet. Good to know. Also had something to do with I had some old code that was setting them to CollisionDetectionMode.ContinuousSpeculative vs simply discrete. This was the bigger issues, setting it back to discrete seemed to "fix" the issue I was seeing even without pooling.
sweet, other strategy i can suggest is to load over time. if you have 100, load 10 each frame for 10 frames
yep another good idea. Using that with my pooling system should smooth everything out. Not sure why the CollisionDetectionMode.ContinuousSpeculative was soooo bad, perhaps that creates an even bigger issue with the spawning collision check. Also seemed like this was exponentially compounded with having a ton of other colliders in the scene (non rigid and non static). My guess is its related to a number of things at this point. CollisionDetectionMode.ContinuousSpeculative PLUS Lots of non static colliders in the scene with spawning (massive lag also happened when the object was destroyed btw so spawn in or out). Would need more testing to figure out exactly what is going on here. Curious if those other colliders where marked static if that would still have caused the issue.
Lots of variables here with lots of combinations to test.
Any one give me a hand. I have a grenade and i want it to ignore certain collisions so i set up a collision ignore in the OnCollisionEnter method that ignore the collision if it should but the grenade will bounce once and then ignore the collision it wont contiune to go threw the collider it has to hit it once first
Any ideas?
I did not create the grenade class im modifying it
Is it something to do with the rigidbody I'm new to unity stuff
mass is 1.0 and its not froze
it works if i make the collider bigger but than it floats
then it's probably stuck in the terrain collider
Solving Kepler's equation by Newton's iteration with inspiration from Kerbal Space Program. These orbits are created from sets of orbital elements and a time variable. The second side of the 'on-rails / off-rails' coin.
some resources on the math:
http://www.braeunig.us/space...
I have this raycast code that is not working. Could anyone tell me what I'm doing wrong?
using UnityEngine;
public class RaycastManager : MonoBehaviour
{
public DoorButtonPress doorButton;
public AddBlackX addXButton;
public AddBlackO addOButton;
public SwitchColors switchColors;
public float maxRaycastDistance = 10f;
RaycastHit[] hits;
void FixedUpdate()
{
hits = Physics.RaycastAll(Camera.main.transform.position, Camera.main.transform.TransformDirection(Vector3.forward), maxRaycastDistance);
SendRaycast();
}
void SendRaycast()
{
for (int i = 0; i < hits.Length; i++)
{
RaycastHit hit = hits[i];
if (hit.collider.tag == "DoorOpen")
{
doorButton.PressedDoorButton();
}
else
{
doorButton.OutOfRange();
}
if (hit.collider.tag == "AddX")
{
addXButton.AddXButtonPress();
}
else
{
addXButton.OutOfRange();
}
if (hit.collider.tag == "AddO")
{
addOButton.AddOButtonPress();
}
else
{
addOButton.OutOfRange();
}
if (hit.collider.tag == "Switch")
{
switchColors.SwitchColorsButton();
}
else
{
switchColors.OutOfRange();
}
}
}
}```
Oh nevermind, it's working now
How do I disable collision between colliders by using the oncollision. Atm it will collide with the collider and then it will ignore. For example a ball must bounce once before it will fall threw the collider
@full warren have to write something custom that changes the collision layer after one bounce (FIrst hit collision layer vs second hit colision layer) or just turn the collider ball off on bounce 2
So do I need to use collision layers?
Essentially i want the ball to allways fall threw
But I wish to use the on collider event as it will be efficient for my use case
As of current say i drop the ball. It collides with the collider, phsyics.ignore runs on that collider and then the ball will fall threw
Does that make sense?
I guess my question is. Can i disable collisions between colliders when they hit each other or do i have to do it before they hit each other?
Hey, I'm trying to do a simple mouse over detection on a tilemap generated through code. But I'm not getting any hit information with this: I'm using a raycast from camera to try and get hit info.
Is there something more I need to do to have the mesh be 'hittable'?
Hey guys does anyone know how they did the gravity/magnetism in wipeout or f zero, trying to make a game like that and need help
I don't know what is Wipeout but you can change gravity direction in unity
Hello I have two object use rigidbody2d I don't want object A to push object B while moving or vice versa
@scenic kite Don't cross-post , please.
Does anyone know how effectors actually calculate the force they apply? I am using PointEffector2D as a gravity source. I would like to calculate the path that an object will follow. I am stuck at accurately predicting how the effectors will apply forces. Any ideas?
I'm looking for an equation that is, or approximates, how they apply forces.
Hi everyone ! I've been using Unity for the past 2 years to make 2D games, but now I'm trying to get into 3D, and the least we can say is that 3D can be ... hazardous
So I'm trying to make a simple rope, by joining small cylinders together with hinge joints, and...
It works "well" when there's only a few cylinders, although they don't really want to "stick" together when I turn the cube too much
And when there's "a lot" of cylinders, well ...
Let's just say that I could use a little help
Can anyone help me ?
Hi, I need a 'https://docs.unity3d.com/ScriptReference/Physics.ClosestPoint.html' variant that calculates a closest not to a single point, but to a line segment. Damn... does anyone here know about some library or what not that could help me with that?
oh geez so you don't need to do a linecast but get the closest point OF a linecast? I have no idea how to do that
@distant abyss Yep, it's a trollish situation. The only thing I could think of is subdividing the mesh (to keep some kind of accuracy of the calculation) I am testing against and the then simply checking projecting each point on the line segment, searching for one with the shortest distance.
But it doesn't sound very optimized. And it will require a lot of work across the board. I will have to weld the mesh vertices to optimize it even more, precalculate it all editor time etc.
I hope someone has a solution for you :x
Hey there, is there any way to prevent the NavAgent from moving before it's completed rotating?
@unkempt vale havent tested it but found this
Hey, I have a capsule collider with a cube mesh renderer and mesh filter. Somehow when the player (a sphere with a box collider) the other object doesnt mover at all. The players mass is 4, the other object mass 1
hey - can anyone sanity-check my understanding?
If I have a propellor attached to a propellor (in air or water, only difference is the variables will go up or down etc)....
engine produces torque (with RPM calcualted based on teh torque curve of the engine)
propellor "recieves" that torque
and then decreases it in proportion to the force created at the prop to move the vehicle forward....right?
(or backwards or whatever - in the direction of the prop's output)
@wraith crown
you should probably have the relative water flow generate some counter torque on the propellor as well
(this is not friction, just waterflow acting on the propellor)
just for example why its necessary i think:
if the ship is statinory, it should be hard to run the propellor on high rpms so then you will have to gear down to have bigger torque on the proppellor coming from the engine
aaah, yeah
but in general my understanding holds up, yeah?
it's a block-based game, so the transmission lines could just have well have a wheel attached instead
so i want to make sure my "model" holds up for any usage cases the player might create
(I know wheel colliders will have to be dealt with separately)
@wraith crown yes
motor RPM curve + transmission level
wheel or proppellor RPM curve
simply put
my plan here is to have a "network" of nodes that connect producers (engines, electric motors etc)
and "consumers" (wheels, generators, propellors)
so if they're linked together, i can add up all the consumers from the last fixedupdate
each "consumer" will obviously take some torque, and do something with it (e.g make electricity, dealt with in another network, or "AddForce" to the vehicle etc)
then the "pool" of all torque used can be calculated each fixedupdate...
and used to adjust the engine torque etc
that sound right?
@wraith crown i had done something like that:
https://youtu.be/0id8yWcxLOU
engine - transmisson - w0,w1,w2,w3
1 + 4 custom rotation joints that only sync rotation on local x axices
engine and transmission are rigidbodies and have inertia and stuff
But i wouldnt reccommend this because joints are springy and and more levels of chaining makes them even springier
yeah I won't do it physically; just the data model etc
gears I'll handle with a "gear block" so if you attach a gear block between an engine and wheel then it'll drop the torque but increase the RPM etc
or....
shared inertia is an issue
are you thinking about that?
not sure; i was thinking that if I calculate stuff like inertia at each "consumer" then it will take the right amount of torque from the network, even tho not all of it will be used for motion, some will be overcoming inertia
likewise gear boxes will change the RPM etc...and knock a little off for inefficiency
lets say your rotate one wheel externally via force
and because how they are connected, the wheel on the other side has to rotate the same way (assume differential locked)
this is a problem if you have this data graphs
wasn't planning on differential...
you need to have a global inertia and a global rpm
it is a building game etc, so not 100% realistic in every way etc..
plus players can add a wheel wherever they like...
what do you mean global RPM?
engine has an RPM, as a producer, based on it's torque curve
any consumers will then consume torque to do their thing (generte power, turn a wheel, a prop etc)
lets say you have a dynamo in the graph,
and it does globalRPM *= 0.97f every frame
and their RPM will be calculated on the RPM that their trnasmission recieves (which might be mdified by gears etc)
when engine stops, wheels stop
or the other way around
urgh my brain is melting
when one wheel stops, globalRPM is 0 so everything else stops im saying
if you could have that kind of system, things would be easy
right so, a graph; producers make torque (based on the RPM in their torque/rpm curve). Consumers, connected via transmission shafts, take torque from the "pool" of produced torque. They do something with it, which in turn affects the torque of the engine, which then drops RPM based on the torque used...
in the case of wheels, the wheel will have to overcome interia and friction to turn at the RPM it's recieving...
if the torque is sufficient for that, it will turn, decreasing the torque avaialble in the "pool"
what's the problem there?
i'm missing somethng aren't i?
if wheel has stopped it means the engine has stopped and engine torque curve is as zero
the vehicle is stalling
@wraith crown
yeah
whilst producing torque that doesn't get used
yep
clutch is 0-1
and a curve controls how much torque is released for each point on the clutch curve
is that right?
and engine inertia will also help when the clutch connects back
(stalling is part of the intended game play. They're designing a vehicle, it shouldn't "work" without effort)
what do I need to do with engine inertia...
for my game, for the clutch, i just multiplier the rotation joints force output
that's inertia that allows the flywheel to keep spinning for a small while even if the torque drops too low, right?
@wraith crown i wanted to make my game your way without joints
and i wanted use graphs like you do
but i couldnt figure it out
so i did it woth joints
@wraith crown yea
my only hard bit here
is how do I calculate the engine RPM
is it solely based on the torque curve?
(cos torque will drop as it's used by wheels, gnerators, props etc)
engine rpm could be the global rpm
i have to think and maybe come up with a complete system
OK so I calculate engine RPM based on the torque curve. The amount of torque is 100-0 based on the throttle
right now, i dont have a complete system if you have more than one source and consumer
and it will decrease based on the load placed on it by consumers eg whels or props
okay heres something
producers will all just feed into the "pool"
there will be no engine physically
and there wont be any states stored for engine n stuff
everytime, you will look at all consumers
and you will figure out a global rpm
engine will not have inertia, if you want extra inertia, you will define a dummy rotating body consumer @wraith crown
you will look at this calculated global rpm and run your rpm curve on that
.
and then you will obtain the engine torque
you will distribute it to global inertia
and depending on the gear ratios
hmmm
theres one last thing
any external forces must be reverted and re- distributed on the whole network
(distributed on global inertia and gear ratios again)
that was my plan - tho I hadn't considered a "global interia" idea, i'm not sure how/what that does
.
you'll be capturing these forces in OnCollisionStay, calculating the torque applied on object, reverting it and reappliying to network
i was looking at "torque" as basically just "mehanical power" which I know it's not
sadly, there could be unlimited engines and unlimited wheels, geenrators, props etc
well, not unlimited cos my building grid is limited in size
you just need
network.DistributeTorque(float torque)
this the main thing
you have this, %80 done
hah, i have it 80-90% planned in my head hahaa
so to summarise
network of produces and consumers; producers make torque based on their internal rpm curve, as a % of throttle.
difficult part is distributing torque based on both inertia and localRPMs(because of gearing ratios)
consumers use torque to do their "thing"; if it's a wheel for instance, the torque required to turn at the "transmission RPM" they get from the linking node might be more than is available, so it turns at a slower RPM
this slower RPM...erm
shit
doubling the localRPM by 2 probably is the same as doubling the inertia by 2
when it comes to distributing the torque btw
i think I'm getting tripped up on the inertia
vaguely remember high school physics
i am 37
that was a lot of whisky ago.
intertia is the energy required to...
take the mass of the object and turn it or something
you need bigger force to rotate an object with same rpm if inertia is bigger
so i handle intertia at the consumer level; each consumer will have an inertia value based on it's cirucmstance (eg. one wheel might be on the ground but another is in the air)
@wraith crown a consumer should affect the rotation of a different consumer all the way across the network
only way to do that right and clean is
laying out some global values
and distributing the force on network
thats the best i can come up with
so
and there is still something missing from my model
wait, if the torque on a given consumer, lets say a wheel
is insufficient to turn at the current RPM it's been given
it will lessen it's local RPM
surely I cn just loop around all consumers and say "hey, what's the lowest RPM" (after correcting for gearing)
and then make that the global RPM
a wheel can be ahead of another wheel rotationwise after running for a while
i dont know how big of an issue it can make
think that would be a fair approximation tho? I just need a somewhat-realistic model that will work if i throw propellors, geenrators, etc at it
@wraith crown localRPM is always gearingRatio * globalRPM
and gearing ratio is kind of a constant
so if the local RPM drops, it drop sthe global RPM
@wraith crown its kind of hard to simulate in my head what this difference in phase
you've helped plenty, thank you.
it's my "understanding" of the basic physics and how best to "fake it" that's my sticking point etc
and you've helped a lot with that, so thanks 🙂
you know what, i think the phase difference is no issue
i'm not even sure what it is 😄
because only way you apply force to the system is this interface:
system.AddGlobalTorque(float)
@wraith crown i said that after running for a while, revolutions each wheel has made will be different even though they have same gearing ratios
foreach (var producer in producers)
{
potentialProduction += producer.PotentialProduction();
}``` is what I am using in the electrical grid code
that woudn't matter, as long as the rpm s equal etc
this one we are talking about is different animal tho
you wont have stalling like we have here with that option
should do
you apply big force to stop one wheel
will the other wheel stop as well in single frame?
the pool has, say, 200 torque, yielding 1800RPM. wheel needs 180 to overcome it's inertia, then 20 to turn but the RPM is waaay down now below the stall level of the egnine, engine stalls
you shpuld be able to do differential lock like connections for starters and then move on to different things i mena
i was thinking a clutch node will split the graph into two graphs
it should stop transmission of 0-1 torque
at will
no cos a clutch isn't 0/1, it's 0-1
when clutch is %100 connected, graphs are merged again
or just do the math so it would behave the same i mean
keeping the graphs disconnected at clutch node permenently
aah
clutch will be like a source and consumer at the same time
whichever part of the graph has bigger globalRPM, applies negative torque
whichever part has smaller globalRPM, applies positive torque
based on difference in globalRPMs
wait that should depend on inertia as well
it's not too simple is i
this itself could do but with inertia it would be more accurate
but yeah, clutches split network
or,,,
... even
clutches make every item "down" from them
a sub-network
with it's own RPM and torque calcs
Hi, I'm working on a marching cubes terrain system in Unity, and I've come to the physics part and I'm unsure as to how to approach it. The method I think will be most effective would be to take the mesh, use a decompose algorithm on it to produce convex mesh(es) from the terrain mesh, then feed these into mesh colliders. However I'm unsure as to whether it will incur bad performance. Can anyone offer any guidance? Thank you!
cos then the "network" is set when they finish building the vehicle and can't be changed etc on the fly..
having an issue with boxcasts
bool temp = Physics.BoxCast(Vector3.back * 15, bounds.extents, new Vector3(x, y, 15), out hit, obstacle.transform.rotation, 1000);
has temp = false when I visually can check that there should be a collision
@little fulcrum you can have nonconvex mesh if the object is not dynamic rigidbody
so just slap the marching cubes mesh on the collider
I'm using a rigidbody for my player and I'd like the player to be able to collide with the terrain
fine
Unless I don't need to use a rigidbody. I'm extremely new to Unity
have the terrain as just collider and visual stuff
no rigidbody
have rigidbody on player or other stuff
you'll be good to go
There's no rigidbody on the terrain, the player does have one and it passes right through the terrain with a standard mesh collider
@little fulcrum you probably didnt set the sharedmesh field in mesh collider of the terrain
I have done so
ignore convex, that was for testing
convex does work, but as you can imagine its unusable
make convex false
k
the mesh is not convex so dont set it convex
and it does not need to be convex
pause the unity when game runs, take a look at the terrain mesh
okay, very strange. If I disable and enable it in the inspector when running it works
click on the mesh field of the collider
@little fulcrum thats the right mesh right?
yea
The same one being rendered
Collisions work perfectly after toggling them in the inspector. Once I configure the mesh am I supposed to call something or update the sharedmesh reference?
maybe restart unity
I've restarted countless times during this lol
because I set the mesh (I think its a reference) then set its vertices etc.
I'll try updating sharedmesh to see
id think its already copied anyways
That worked, setting it after configuring the mesh
So I do this instead and it works fine lol
yeah, no methods on it like that, but this seems to work fine lol
maybe it is copying for safety?
it is a property
its probably a getter/setter
Yeah, it is
with wrench icon i mean
then its basicly a function
must be copying it
i never had to make a copy of the mesh
huh, oh well, at least it's working as intended now (and I've not wasted countless hours implementing a decomposer). Thank you for your help!
np
figured it out, was moving colliders in the same timestep
Is there anyway to remove wheel collider suspension withotu causing chattering of the vehicle and other weird behaviour?
@slim olive that will probably work. Or use a spring joint.
could be easier to control the player velocity in-script
would be more predictable than a joint
Is it possible to disable collisions between childs of two seperate parents in a 2D game?
@sharp ruin you could just use the collision layers
@sharp ruin if you are fine with 3d physics just move them in z axis and lock x,y rot and z pos
if you wanna get real fancy, try to see if you can get the objects in seperate physics scenes
do you think 3d components like rigidbody, collider dont make any problems in 2d game? I mean, are there any games using this type of convention. This is my first product-level trying so I dont know that much of its practices. And... We use tilemap-2d. Interacting 3d objects like rigidbody and collider with 2d-tile map makes me think that this might cause a problem in the future?
there are many
@sharp ruin i'd try to have the 2d phyiscs if i have more than 20 moving at a time and if its a mobile game
@sharp ruin you know how collision layers work?
its probably what you want
its a 2d desktop platformer game.what we really want to do is creating 3 different "dimensions" back to back shown below and we dont want interact any of the objects in one "dimension" with the objects in rest of the "dimensions". we only want to render objects of the dimension that the main character is in whereas the objects in all dimensions keep moving and interacting as they did. and we dont want to disable collisions based on layers(as dimension1, dimension2, dimension3) because we have different layers for every different type of object @viral ginkgo
@sharp ruin if its going to be just 3 layers like that, just switch between the 3 collision layers
Are collisions layers something different than layers?
But all of the child objects have their own layer like Player, tile etc.
and in collision matrix, you'll do adjustments to prevent 8ntercollision between these layers
@sharp ruin you will make sure all those child objects of the same parent belongs to to the same layer
dont do the parenting if you want
not necessary
you have to make sure each child object have their layers correct
I see your point but I dont think it works. Here is why: We dont want to disable collisions in different dimensions based on layers because we have already different layers for every different object in our game such as bot1, tile1, tile2, player, ... etc for other purposes. Besides, if we narrow layers down to three, this will make us not taking advantage of layer based collisions for other purposes
yes, that will prevent you from using the layers for other purposes
you could consider switching physics scenes then
can you provide some documents to learn more about physics scenes
@sharp ruin it might be easier to just use different scenes
but if you have two different running at the same time, i believe they will use the same physics scene by default
so you will need to instantiate and assogn a new physics scene for each scene
i messed with these before
but i dont remember where i got the info from
@sharp ruin
https://forum.unity.com/threads/separating-physics-scenes.597697/
could check this out
I will check thanks for your time
I would like to work on a game involving collisions between many fast-moving small lightweight objects sliding along a surface. Think Marbles, or Air Hockey. Would Rigidbody Physics be able to handle this sort of thing, or does the collision system break down at those levels of precision? Are there any other physics system Assets anyone might recommend for something like this if Unity's built in physics aren't up to the task?
many fast moving objects colliding with eachother isn't something PhysX does particularily well. Try t out and see, but you'll most likely switch to bullet or something
PhysX is Unitys out of the box physics engine, right? Or do I need to grab an asset or something for that?
it's out of the box yes
And where can I find Bullet? Looking for "bullet physics engine" just brings up like, physics for bullets. Is it a different engine?
Cool beans, I'll give that a go
or make your own physics.
I find that physx either does way more than you need, or fails in the particular aspect that's important for you
Until now I've done my own physics and collisions, but for this project I kinda want realistic bounces, impulses, and ricochets and I feel like this is literally what physics engines are built for
For my main movement I am trying to have a player rotate around the center point of a disc.
Moving left should rotate clockwise around the surface of the disc, moving right should rotate counterclockwise.
The y rotation of the player starts at 0, at the location [0,0,-48000], and as I rotate around the origin point of [0,0,0] that rotation of y axis changes accordingly, however when I attempt to return to my spawn position [0,0,-48000], where I expect to see rotation of y axis to return to zero, it is a different value other than zero.
What is happening with this rotation?
Hey can anyone tell me which unit is the weight of a rigidbody ?
@urban geyser kilograms. Those values make sense if your distance/scale is that 1 unity unit = 1 meter
thank you
ok i think this is the right place (i think) So im tryng to replicate savavs parkour mod from gmod (Link Below) and id like to ask which would be the best thing to use:
Character Controller Or RigidBody
and also can you provide a link to help me make one of these
https://www.youtube.com/watch?v=TxubrgxD4OU
(i dont need the gun just camera movement and detecting walls)
Subscribe to Scornex!: https://goo.gl/FnqYdP
Subscribe Plz :D? http://goo.gl/hTyDU8
Subscribe to My Vlog Channel: https://goo.gl/Ug1Zdf
Discord Server: https://discord.gg/McG9DpW
Facebook: http://goo.gl/fOI4u3
Twitter: http://goo.gl/6JRc73
Twitch: http://goo.gl/itz7AO
Hey guy...
https://www.youtube.com/watch?v=Tow-GlsERJg how can i fix this issue with springs and dampening?
i need dampening to be 1000 AND for vehicle to be movable both at same time
@stuck bay maybe your tank is too THICC
?
compared to the rigidbodies that have the wheels
its 1000 mass
what about the wheel objects?
I think if you shifted some of the weight the wheel objects, it should be fine
how are they not flying off of your tank
Make body 200, wheels 50 each
or something like that
Or, attach the wheels on the 1000M body directly
the force required to keep your tank from crushing your wheels is probably larger than any force the wheels are generating
@stuck bay Joint strenght seems to depend on the mass of the object its attached on, for all kinds of joints
i made each wheel weight 1000, still doesnt want to move
force is tilting the object, but cant move it
just set everythings mass to 1
try to have default values in spring, dampening and stuff
when you get it right, multiply everything by 1000 or something
they do work on default, but theyre static af, the tank has no acceleration movement
then more motor force
if i set springs to 10 000 and dampening to 10 000 with wheel mass 1 it moves. but thats 10x as much dampening as i need
No. Im applying it to the tank.
Wheel colliders serve as suspension only
@stuck bay you are doing addforce on the tank??
yes
can i tell them to accelerate 10m/s, decelerate by that etc?
you are just applying linear force at the center of mass and expecting the object to tilt
@stuck bay
no, im expecting the object to move.
The object moves, if the suspension is ridicilously high
but i dont want it to be high
At least you can just apply the force from below the center of mass
AddForceAtPosition(yourForce, transform.position + Vector3.down * 2);
for what effect?
@stuck bay it will push the tank from bottoms and give you what you want
but its not the correct way
just so you see what i mean
you get your wheel motors right, and you will have your tilt, and dont do the addforce
you should be able to
if you had some drag or friction in wheels
i never used those wheels before but there has to be that kind of stuff
i looked at wheel scripting api, it has nothing about accelerations etc
it should have "motor" stuff i think
https://www.youtube.com/watch?v=wR4TPKbejpc u mean add forces like this?
no
whats the code that applies force
you replace that line with this:
"AddForceAtPosition(yourForce, transform.position + Vector3.down * 2);"
there is motor torque, but i dont have any idea what it is and it doesnt have values for acceleration etc
and your tank will tilt
im using the wheels to suspend my tank a lil bit above the ground as well
@stuck bay Use Motor, motor speed and max motor force
that stuff
if you will use the motors forget this:
"AddForceAtPosition(yourForce, transform.position + Vector3.down * 2);"
im on 3d, not 2d
https://youtu.be/1FHMGar83Xc?t=68 if i dont make the vehicle hover this happens because unity
yes
i have wheel colliders
what joint are they connected with?
they should be connected to the tank with joints
why?
and you should be applying rotational force to rotate them
or use joint motors
if you want to do that with wheels
i dont. Wheels have suspension, therefore im using wheels
or you'll just do some custom code in OnCollisionStay
And simulate what a rotating wheel would do
The only thing wheels do is provide me with suspesion
or you'll just do some custom code in OnCollisionStay
And simulate what a rotating wheel would do
@viral ginkgo
Then this is what you can do
Looking at relative speed to the ground, applying forces
but im not using a single rotating wheel, neither i need to.
i press W, object moves forwards.
Simple
no massive torque calculations for acceleration or whatever.
or you'll just do some custom code in OnCollisionStay
And simulate what a rotating wheel would do
For this, you dont need rotating wheel
But if theres a force or friction apply, you should do it by the wheels
Do grounded check in wheels, figure the force from the wheels relative speed to the ground
and i have tank physics maker asset which is based on torques etc, and its doing the job i need really badly.
By wheel, i just mean that non rotating thing you have under your tank
for example, i have a hull which needs to be with 1100 mass and it needs to move 13 m/s. With that asset i need to make each wheel 2500kg and its still barely reaching 12.5 m/s
Thats why i dont want to use it
.
Or heres the simplest thing i can come up with
1- You do grounded check and then apply your force
2- You prevent velocity that is perpendicular to the tank.forward
3- You apply the forces from bottom of the tank via calling AddForceAtPosition on the tank instead of calling AddForce (this is just to archive that realistic tilt you want)
@stuck bay
Other then these, you keep the setup same
im already checking for ground. Red gizmo cubes meant that it doesnt detect ground, yellow means that no suspension is active, but tank can already drive, green means the tank is fully on ground
@stuck bay then you have 2 and 3 missing
yeah. i dont rly know how to do 2 and 3 made my tank bounce
If you did all this per wheel collider thing, you will have better realism
You could also multiply the wheel force with suspension tension
@stuck bay you did the 3 wrong
yourforce is the driving force
not some weird upward force
https://www.youtube.com/watch?v=8Hg1f4hgxzc im trying to recreate these physics
Thanks For Watching Like and Share The Video
Join my Discord server: https://discord.gg/9JH7cxp
Music down 👇
Music
- Migos & XXXTENTACION - Look At Me! Bad And Boujee (Mashup)
Link: https://www.youtube.com/watch?v=C1lZlSAcAcM - blackbear - Wanderlust (WILDLYF Rem...
that line is long gone for bouncy tank
that particular line of code that is responsible of moving the tank
give me the line that is reponsible for moving your tank you are using right now
`
thisRigidbody.AddForceAtPosition(transform.forward * stats.Acceleration * ((1f / trackCastRight.Length) * (activeRightTrackPoints)), trackCastRight[2].position, ForceMode.Acceleration);
and cs
there are massive chunks of code commented out. Those are my previous far more complicated unsuccessful attempts
thisRigidbody.AddForceAtPosition(transform.forward * stats.Acceleration * ((1f / trackCastRight.Length) * (activeRightTrackPoints)), thisRigidbody.transform.position - thisRigidbody.transform.up * 3f, ForceMode.Acceleration);
fixed something
copy now
replace that line
with my code
thisRigidbody is... this rigidbody.
stats.Acceleration = 10
trackCastRight/Left = how many cubes in each side
ActiveTrackPoints = how many of those cubes are touching ground
oke changing
@stuck bay i just looked at the code
i was expecting one force
found one force per wheel thing
well, force for each track.
each track that is grounded?
no. Each track has 5 points represented by cubes.
if all 5 cubes are on ground, the track is accelerated by 100% speed
doesnt matter at all anyways
if 1 cube is on the ground, the track is accelerated by 0.2% speed
@stuck bay the version you sent me now should be giving you the effect
maybe suspensions are stiff
if not
then you could try this for each of those forces
i did add ur code, yeah, i need to adjust the values, cause it was trying to flip the tank, but yeah XD
flips it the correct way? @stuck bay
my code will basicly move the force a little lower
to boost the tilt
the force will come below the wheel
yeah, it did flip it the correct way, but too much
@stuck bay if you check each wheel for grounded and apply force depending on that, it will be more realistic and wont flip
even with 3
because if the tank starts flipping, only the most backwards wheels will generate force
i am checking for each grounded wheels
but force has 1 multiplier for all wheels
And i am applying acceleration based on how many wheels are grounded
can i apply acceleration multiple times per update?
if each wheel accelerates object by 1 m/s, and all 10 are on ground, will it be accelerated by 10 m/s?
no
then that doesnt fit my needs
acceleration mode will just apply the force to make that object accelerate at given value in empty space with no gravity
its just a force
with mass as a multiplier
even my current system doesnt fit the needs, because it can reach speeds beyond maximum speed
yeah, i know. And i got no idea on how to get excatly precise coeff to get it
i have js code for suspension etc, but i got no idea what any of it means.
frictionForce = Vector3.Project(relativeVelocity * -0.1f, groundNormal);
and how is that going to limit my speed to 10 m/s?
force is same, friction increases linearly with velocity
this effectively gives you a max velocity
so i add this code to each wheel?
yea
relative vel wont change much per wheel
doesnt matter much
but since you add the forces per wheel, might as well do this per wheel
.
i have some assignment i should get back on good luck
xd
@viral ginkgo wheel colliders have their own suspension so i don't get why they need joints as well.
@stuck bay dont worry about that, it was for archieving rotation on the wheels
but we decided not to use rotating wheels
for visual wheels there is a function for that
this was for physics part
i offered the rotating wheels for accurate physics
but that may not be the best way
limiting your speed however is just this
if rigidbody velocity.magnitude > maxspeed dont apply torque to wheels on this current frame.
i thought thats not very natural
here an example:
you speed up the tank, below the max speed
and stop pressing W
tank will glide forever on flat road
this could go together with what i offered tho
you can also scale torque based on speed
var linear = 1.0 - clamp01(velocity / maxspeed).
wheel.torque = maxtorque * linear.
^ apply less torque at max speed.
If you want to decelerate without breaking - you can apply a little bit of reverse torque
but also have drag on rigidbody
@stuck bay theres no rotating wheel, therefore no wheel torque
only linear forces at wheel positions
so he isnt applying power through the wheel colliders?
ihave a code which checks if the tank is moving faster than maximum speed, it decelerates the speed
no.
I used wheel colliders purely for suspension
@stuck bay just linear force, no actually physically rotating wheels
error = currentspeed - desired speed
rb.addforce(error * scale)
something like that then
that would be kinda suddent drop in the speed
same as what i offered in practise but desired velocity is 0
@stuck bay
if desired velocity is 0 then error is actually inverse of your current velocity
yes
so all you need is to scale it and apply it
this is just modelling friction
not like max speed or anything
max speed comes natually
.
because friction increases linearly as velocity increases
and forward force is always same
imagine the graph (force/velocity graph), a flatline and a diagonal line
the point they intersect is the max speed
but when desired speed and current speed intersect your error is zero - which is the point where you are traveling at max speed until you set a lower desired velocity.
So there is a point somwhere I am missing?
yeah, but i tried the line, rigidbody.material.dynamicFriction can be only float, not vector3
@stuck bay yes
if you are at 0 velocity, it will try to speed up
and this is for friction
you mean this is just for controlling velocity?
then can work
pretty much same effects as when you do "force + friction" in my model
because the friction is linear
I don;t know if im the confused one or not but the error would be used in both accell and decel.
I see
Its pretty much same as what im doing when you combine the friction and force in my model as i said
idk
i was thinking about something like this
float desiredSpeed = Input.GetAxis(someAxis) * maxSpeed; // some input * maxspeed.
// velocity in relative space:
var localVelocity = transform.worldToLocalMatrix.rotation * rb.velocity;
// our current speed is down Z:
var currentSpeed = localVelocity.z;
// the difference between our current speed and our desired speed,
// regardless of if we are moving or stationary...
var error = desiredSpeed - currentSpeed;
if(error < 0)
error *= somevalue;// we can scale it to control braking force
else
error *= someOtherValue; // we can scale it to control accelleration force.
rb.AddRelativeForce(Vector3.forward * error * someScalingValue);
because regarless of input, your vehicle will try to match whatever desired speed is along it's Z -Plane
you can then just use Drag to control friction as well probably.
then what am I misunderstanding :/
i told you they are the same
ok
is there a youtube tutorial or something on this force max speed thing?
I figured there is some other objective I was missing. I guess not.
nope
@stuck bay - it's basically just relativity.
i need coffee and to murder my pillow. have fun.
of which i know nothing about
but if you keep friction seperate to forward force, its just easy to change how friction works
like quadratic friction for example
it would be hard to archieve with your code
2 AM here, gotta wake up at 7 AM, a bit too late for me to go to bed XD
i tried many different ways. i just cant wrap my head around them
1AM here.
2am here too
I am in tthe past - speaking to the future.
from these values i need to make the physics
As thats mostly all i know
i just see multipliers to some vectors
i mean wouldnt mind if Top_Speed = 10 is 24.54213f units per second in unity
i see bunch of nonsense ifs and bools, thousand line code which does absolutely nothing
wait, so unity isnt m/s?
meter, kilogram, second
yeah. The tank is meant to move 10 m/s
1m is lenght of the default cube
you could figure out how to make it 10m/s with that graph or OTAKU's code
from what im understanding, otakus script doesnt account for acceleration/deceleration etc
you just set target speed
that can be 14m/s velocity or 10 m/s velocity in either dirrection.
maximum speed is dynamic.
you can have like max forward speed, max bacward speed
desired speed
and just clamp the desired speed between the two
while giving user full control of the desired speed
but if i clamp the velocity, wont it go at 14 m/s and then suddently drop to 10m/s if the max speed changes?
now im decelerating it and the max speed moves somewhere from 8 m/s to 12 m/s randomly
@stuck bay no, you are not clamping the velocity, you are clamping the desired velocity
and then your forces make the velocity match the desired velocity
im about to give up on the god damn velocity thing and let the tank move as fast as long the user hold velocity...
cause honestly i understood nothing about the friction thing, my tank wiggles when its on low velocity and rapidly changes velocity when its at its max velocity.
how much would it generally cost to get someone to make hull physics like this?
https://www.youtube.com/watch?v=8Hg1f4hgxzc
Thanks For Watching Like and Share The Video
Join my Discord server: https://discord.gg/9JH7cxp
Music down 👇
Music
- Migos & XXXTENTACION - Look At Me! Bad And Boujee (Mashup)
Link: https://www.youtube.com/watch?v=C1lZlSAcAcM - blackbear - Wanderlust (WILDLYF Rem...
ive spent weeks on it and i cant even reproduce the hull suspension
I am experiencing some bizarre jittering, rotation and micro translations when moving across the ground. Anyone know what could be causing this?
have you using a sigle object for the blue ground and the purple @broken frost ?
@stuck bay well what i did was using normal wheels. To each wheel was connected a bone that deformed the track when moving up and down.
Hello,
What's the best way how to cloth hair bones.
@glossy canopy hae you looked some hair shader asets on the aset store ? Ok it can be difficult to have one for free in but try ;).
well i have character with hair and hair bones
not sure if i want low poly model alias polygonal hand painted model with hair shaders 🙏🏻😁
meant to ask this in here!
if I'm tying to work out what the new RPM/torque of a drive shaft is, after connecting a new shaft/power source...
if the RPM/torque on one side is, say, 100RPM and 2 Nm, and the other is 50RPM but 5 Nm
Idk me too and Im only using add force sorry
how do I work out what it will be