I have been creating a physics Model Newton Cradle(pendulum) in Unity 3D, but have been facing difficulties in rotating and zooming camera around object, applying momentum conservation for pendulum objects.
I'm not sure if this will help but based on the title of this statement[?] I'm guessing you want to rotate the camera around a target. This is some simple code that may help you on your way.
target=GameObject.FindWithTag("Cradle").transform;
transform.LookAt(target);
transform.Translate(Vector3.right * Time.deltaTime*2);
edit the number after deltaTime to change the speed and the Vector 3 for the translation. Obviously change "cradle" to whatever the tag of object you want the camera to focus on.
Related
I want to do when a object moves camera will smooth that move. I can only explain this with images.
Is this possible and what is name of this effect. And is this possible for 3D objects (or only 2D).
The effect that you're looking for most likely is Motion Blur. You'll have to look into Post-Processing for that.
Here's a resource:
https://learn.unity.com/tutorial/post-processing-effects-motion-blur-2019-3
I'm having a lot of trouble figuring out how to orient my model. I noticed the problem when I ran into trouble getting my character to rotate in the direction of movement. After significant trial and error with functions like LookAt() I realized it was because my character's z axis (forward vector) was not facing the same forward direction of the character. After rectifying this in Blender I imported into Unity and walah the z axis is in the same direction as the character. But when I play the game and the animation starts, the z axis points in the wrong direction again! Any idea why Unity is doing this? fyi I modeled the 3d object in blender.
AFter starting the game (character doesnt face z axis) :
Before starting the game (character faces z axis)
If your scene is modified when starting the game you can assume that it's logic you've created, likely scripts, that affect the Game Objects.
Like the comments suggest, try disabling the script components on your game objects to see what causes it.
Sometimes you may want this logic in your editor scene, so that your Objects are rotated the way they will be when the game starts even when you're working with the scene.
Imagine having a top-down game with a camera that follows the player and is always rotated towards the Player. You'd want this camera to rotate towards the player when you move it around, re-arranging it so that it gets the perfect angle. To achieve this you may use [ExecuteInEditMode]:
[ExecuteInEditMode]
public class LookAtPlayer {
Transform player;
void Update() {
this.transform.LookAt(player);
}
}
If you have re-imported your model and adjusted it's X/Y/Z axis while already having created an animation, then it is very likely that your animation is using the wrong Axis.
You can either copy the values of your animation onto the correct axis, or if the animation isn't very complex I advise you to recreate the animation from scratch.
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 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.
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.