rigid-bodies

Frame-rate independent pushForce?

狂风中的少年 提交于 2020-01-06 06:18:05
问题 I'm working with a CharacterController and added the ability to push Rigidbodies. The problem is however that the pushing is frame-rate dependent. How would I be able to make it frame-rate independent? I have tried adding Time.deltatime, but this makes pushing not possible, I might be adding it wrong though. Here's the code that adds force to rigidbodies; void OnControllerColliderHit(ControllerColliderHit hit) { Rigidbody body = hit.collider.attachedRigidbody; if (body == null || body

How to avoid overlapping of GameObject without rigidbody?

时光毁灭记忆、已成空白 提交于 2020-01-06 04:31:11
问题 I was looking for a way to make my gameobject not overlap to the another gameobject but all the solutions are talking about Rigidbody.. when i want to do it in script only without rigidbody, is it possible ? I have a cube with this scale (3,1,1) I make him rotate around itself but i got the overlap problem because his x scale is 3 Is there anyway to make him move and back automatically to avoid the red gameobject? image 回答1: you can use this method GameObject myDraggedGO; // parent private

Unity collider going through other colliders at times?

三世轮回 提交于 2019-12-24 17:18:13
问题 I'm trying to create a Pong clone for practice. I setup my project in 2D. The paddle has the following components: -Rigidbody2D (set to kinematic ) -BoxCollider2D (is a trigger ) The ball has the following components: -Rigidbody2D (set to kinematic ) -CircleCollider2D (is a trigger ) The paddle is controlled via dragging (user dragging finger on screen left/right). I used the EasyTouch plugin for this. Then I move the ball with this script: void Update () { transform.position += new Vector3

Bullet Prefab Script

雨燕双飞 提交于 2019-12-20 06:05:00
问题 I am getting an error in this script? UnityEngine does not contain a definition for rigid body (Lines: 22,24) public class GunShoot : MonoBehaviour { public GameObject BulletPrefab; public float BulletSpeed; public int BulletsInClip; public AudioClip GunshotSound; void Update () { if (Input.GetButtonDown("Shoot")){ Shoot(); } } void Shoot() { var bullet = Instantiate(BulletPrefab, transform.Find("BulletSpawn").position, transform.Find("BulletSpawn").rotation); bullet.rigidbody.AddForce

Predict the position of a Rigidbody Object in x second

南笙酒味 提交于 2019-12-18 04:23:39
问题 Let's say that you have a Rigidbody Object that moves. Force is added to this Object via Rigidbody.AddForce or Rigidbody.velocity . The Object can roll hit another Object and change direction. I know about Extrapolation but in this case, it's nearly impossible to use some formula to obtain the position of the object in x seconds, since the Object can hit another object and change speed/direction in the process. Unity 2017 introduced Physics.autoSimulation and Physics.Simulate to solve this

moving physics body at a constant speed

偶尔善良 提交于 2019-12-13 05:08:56
问题 I am working with a 2D physics engine that has the typical physics properties on a rigidbody get/set mass, friction, bounce, gravity, linear damping, linear velocity, impulses. I would like to move this rigidbody at a constant speed, is there some formula that I can use to uses those forces to move the body at a constant speed. 回答1: Constant speed can only be achieved in a universe with no other matter. So, you've got to remove friction(no air to bump into), gravity(no other mass pulling on

I want an Object lerping in the y-axis to move along the Z-Axis?

女生的网名这么多〃 提交于 2019-12-11 15:45:08
问题 I'm currently making a runner type game that is not randomly generated in Unity. The player, camera and background stay in the same place (the player movement is clamped) and the hazards come towards the player along the negative Z-Axis with this simple lines of code: public float speed; private Rigidbody rb; void Start () { rb = GetComponent<Rigidbody> (); rb.velocity = transform.forward * -speed; } And it works fine. Now I want to add asteroids that not only come towards the player, but

Calculating Rigid body Inertia Tensor world coordinates

混江龙づ霸主 提交于 2019-12-11 03:46:50
问题 I'm trying to implement a small rigid body physics simulation, using DirectX to draw my objects and its Math library to take advantage of SIMD calculation (XMMATRIX and XMVECTOR classes). My question is about the Inertia Tensor , I know that using its inverse I can calculate the angular acceleration like so: AngAcc = Inverse(I) * torque and that inertia tensor, in local space, is constant... so I have store its inverse in my RigidBody class with some other members: //'W' suffix means 'world

RigidBody2D freeze X position

谁都会走 提交于 2019-12-07 13:17:25
问题 I'm wondering if there is a way to emulate the following line of code using Unity's RigidBody2D as opposed to using a normal RigidBody. rigidbody.constraints = RigidbodyConstraints.FreezePositionX; I wanting my players x position to freeze when it collides with something. Whilst I could use the above, it would require I rework all my 2D collisions to work with the 3D collision. A pain I'd rather avoid. 回答1: This is due to the Box2D engine use to do the simulation. It does not directly provide

RigidBody2D freeze X position

我们两清 提交于 2019-12-05 23:56:49
I'm wondering if there is a way to emulate the following line of code using Unity's RigidBody2D as opposed to using a normal RigidBody. rigidbody.constraints = RigidbodyConstraints.FreezePositionX; I wanting my players x position to freeze when it collides with something. Whilst I could use the above, it would require I rework all my 2D collisions to work with the 3D collision. A pain I'd rather avoid. This is due to the Box2D engine use to do the simulation. It does not directly provide a constraint on the rigid body itself. It does however provide joints. What you want to look into is a