I am stuck with two things while trying to simulate the physics setup for a trolley-like object (push powered vehicle with free rotating wheels on the front and fixed wheels on the back).
I have the RigidBody with its mesh and four WheelColliders, the object moves fine if I just apply torque to the wheels. However if I use the AddForce method on the RigidBody it won't move; I see the object being pushed (slightly balancing) but the wheels won't rotate so it stays in place. How can I get the wheels to move if the object is being pushed?
My other problem is to simulate the standard 360 degrees rotating wheels on the front of the trolley. What would be the best way to simulate this? I was thinking about a horizontal WheelCollider and a vertical one as a child but that seems really weird and I doubt it will actually work. Any ideas?
https://docs.unity3d.com/Manual/WheelColliderTutorial.html
This tutorial shows an example of how to use the wheel colliders and apply steering and torque to them.
It might be what you are looking for in regards to the adding force part.
I suspect it might allow the 360 degree rotation as well, but I am not familiar enough with these colliders to guarantee that.
EDIT:
In the guide there is the line:
public float maxSteeringAngle; // maximum steer angle the wheel can have
Which looks relevant for the 360 degree turning.
Related
I was wondering if you could tell me if this is possible. I've spent a couple hours to no avail trying to find a way to make a object with box collider swing inwards and outwards like a door. I used hinge joint, but it will only swing the gameobject inwards or outwards around the joint. I am trying to achieve a 'saloon door' effect that allows free rotation around the y axis. I have tried fiddling with the anchor position and axis values but no luck. I was surprised not to find any similar problems online, perhaps hinge joint is not meant for this purpose? Any clarification is much appreciated.
I'm not really sure how I fixed it, but I got the door to swing freely. One possible reason is surrounding colliders or terrain prevented it from swinging freely. sigh
I'm trying to make a car (or any object) in rotate when sitting on a plane surface or inside a tube shape. Currently the car acts like it has 0 grip on those surfaces (even tough the car moves without any problems when accelerating, but the objects don't move the car)
What I've tried so far:
putting a Physics Material on the tube & plane but has no effect
tuning the parameters of the Physics Material, no effect
marking the animation's Update Mode of the tube and plane as "Animate Physics", no effect
increasing the traction of the car (uses RCC), no effect
increasing the mass of the car..nothing
increasing mass of wheels, nothing
tried googling the problem, either didn't write the right terms or just couldn't find anything
Any help would be appreciated.
Thanks!
You need to rotate the plane and the tube using their Rigidbody with the AddTorque method or similar. If you just rotate them via their transform it has no effect on the physics system.
I have this ball that i want to move by rolling like a certain alien, with it spinning on its transform.up to change its direction and rolling on its transform.right to move forward and backward. But as it rolls, its up and right transform vector gets messed up.
In the end, i was unable to find a way to allow it to roll without messing up my directions vector. I have no clue as to how to do this. So yeah, please help. ORZ. By the way, i'm not creating a game using the Ben10 franchise. The ball should act like a wheel... a really round and spherical one.
Note:
I want to use physics in this game. Since, i want it to be able to launch itself off a ramp or something. So, only addforce or addtorque or other relevant functions.
I want to move a cube by making it roll on it's edges. The cube will be standing on a x-z grid and each movement it takes will make it stand on a different square of the grid.
The player will controll the movement and will only be able to make the cube roll on one direction at a time (left, right, forward or back), but the cube must always stand exactly on top of one of the grid's squares.
I don't think applying a force to the cube will help cause it could move it a little bit too much or too little. I want to achieve something like this: https://www.youtube.com/watch?v=yaAIUYuNi84 but only on the x-z plane. Notice how on each corner the cube can stop and change direction with ease, because it never moves too much or too little.
Any ideas on how to approach this?
If you are new to the Unity it will be useless to trowing you a bunch of codes so i am telling you the way of doing it so you can implement your own codes.
You can create 4 empty game object which will always follow the cube on the floor and when you want to roll the cube you will rotate the cube around the empty objects.
You can find the codes for following the cube and rotating the cube on youtube, and for the starters searching is allways good.
So i hope you can manage it out, if you cant please write me again where did you stuck and i will be happy to answer you :)
I am looking for some info on how I can get my sprite to change its rotation by changing the angle of the sprite.
Basically here is how it is set up. Imagine a rocket that is sitting in a stationary position. The physics body is the shape of the rocket, with the tip pointing to the top. Now I apply an immediate impulse to the rocket to send it into the air. While in the air, I would like to use the accelerometer to rotate the sprite. With the rotation, I am expecting the direction of the sprite to change. Unfortunately, The sprite goes straight up and down instead of the direction it is rotated, even though the texture and physics body is rotated. I am having a hard time trying to find info on what techniques are used to achieve the results I want. Most examples have a continuous force, but I only have the initial force with no change after that. I have played around with linearDamping and angularDamping, but that was no help. I have also tried attaching another physics body to the tip to make the tip more heavy to see if the direction will change, but that didn't help either. My only work around that worked is to change the gravity direction, But I would like to avoid this. Any help or direction would be appreciated.
I think the solution you may be looking for is in Sprite Kits SKFieldNode class.
https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKFieldNode_Ref/#//apple_ref/occ/clm/SKFieldNode/linearGravityFieldWithVector:
The linearGravityFieldWithVector: is probably your best bet. It applies a linear gravity field in a direction you set.
You can also check out electricField which is similar however you can change the charge to positive or negative.