this is car controller      using UnityEngine;     using System.Collections;     using System.Collections.Generic;      public class CarController : MonoBehaviour     {         public float acceleration;         public float steering;         private Rigidbody2D rb;          void Start()         {             rb = GetComponent&lt;Rigidbody2D&gt;();         }          void FixedUpdate()         {             float h = -Input.GetAxis("Horizontal");             float v = Input.GetAxis("Vertical");              Vector2 speed = transform.up * (v * acceleration);             rb.AddForce(speed);              float direction = Vector2.Dot(rb.velocity, rb.GetRelativeVector(Vector2.up));             if (direction &gt;= 0.0f)             {                 rb.rotation += h * steering * (rb.velocity.magnitude / 5.0f);                 //rb.AddTorque((h * steering) * (rb.velocity.magnitude / 10.0f));             }             else             {                 rb.rotation -= h * steering * (rb.velocity.magnitude / 5.0f);                 //rb.AddTorque((-h * steering) * (rb.velocity.magnitude / 10.0f));             }              Vector2 forward = new Vector2(0.0f, 0.5f);             float steeringRightAngle;             if (rb.angularVelocity &gt; 0)             {                 steeringRightAngle = -90;             }             else             {                 steeringRightAngle = 90;             }              Vector2 rightAngleFromForward = Quaternion.AngleAxis(steeringRightAngle, Vector3.forward) * forward;             Debug.DrawLine((Vector3)rb.position, (Vector3)rb.GetRelativePoint(rightAngleFromForward), Color.green);              float driftForce = Vector2.Dot(rb.velocity, rb.GetRelativeVector(rightAngleFromForward.normalized));              Vector2 relativeForce = (rightAngleFromForward.normalized * -1.0f) * (driftForce * 10.0f);               Debug.DrawLine((Vector3)rb.position, (Vector3)rb.GetRelativePoint(relativeForce), Color.red);              rb.AddForce(rb.GetRelativeVector(relativeForce));         }      }   and this is camera controller  using UnityEngine;  public class CameraController : MonoBehaviour {      public Transform player;     public Vector3 offset;      void Update()     {         transform.position = new Vector3(offset.x + offset.x, player.position.y + offset.y, offset.z); // Camera follows the player with specified offset position     } }
123363
I created 3 boxes, then align the three to form some sort of a gate, I set the parent to an empty object so that I can easily move it. And I add box collider inside the gate.     When I try to rotate it on Y axis, the boxes deforms    I just want to rotate the Y, not deformed it. Here are the object          Is this related to the transformation I created before?  Something that requires to apply the transformation first? like in blender3d?
38481
In my book, the following are described to be the steps that one must follow if he wishes to find the direction of static friction force acting on an object:  &quot;(1) Draw the F.B.D(free body diagram) of the object in question with respect to the other object on which it is kept. (2) Include the pseudo force also, if the contact surface is accelerating. (3) Decide the direction of the resultant force and resolve this force into two components; one along the surface of contact and the other along the normal to this surface. (4) The direction of static friction is opposite to the component of the result force along the contact surface.&quot;  Firstly, are these steps correct? Will I always obtain the correct answer by following these steps? Secondly, consider the following problem:  In questions like these, when I try to find the resultant force and then assign the direction to static friction, I find that my answer is incorrect! Are there some other steps to follow when I know that the object is definitely accelerating in one direction or another? Edit 1: I approached the above question by doing exactly what my book suggests; first, I identified all the forces acting on the smaller block, being the normal force applied by the block A and its weight mg downward. Adding these two forces, I get another force that actually acts on the body like so:  I wonder if I'm not supposed to take either of the contact forces into consideration when drawing the F.B.D to figure out the direction of static friction acting on the body. Also, are there other steps for finding the direction of kinetic friction? Edit 2: From Judge's answer, I have been able to figure out my mistake, it being that I completely missed step (3) and didn't resolve the resultant force into components! Sheesh. Sorry! Much thanks in advance! :) Regards.
118519
I would like a button in my gui menu to follow a specific path if we selected it, I am wondering how I could do it: if we touch the button, then it can only move on the specific path, it is an arc such as this path :    Would you know how to achieve this? I am using Unity, but I think the theory should be the same for other software/language ?  Thanks for your help  __  EDIT:  here is the code for the bezier curve in unity : Where should I put the script?  using UnityEngine; using System.Collections;  public class DrawBezierHandle extends Editor {      public Transform startT;     public Transform endT;      function Start(){         startT = GameObject.Find("start").GetComponent("Transform") as Transform;         endT = GameObject.Find("end").GetComponent("Transform") as Transform;     }      function OnSceneGUI() {          var width : float = HandleUtility.GetHandleSize(Vector3.zero) * 0.1;         Handles.DrawBezier(startT.position,                          endT.position,                          startT.position * 5 * Vector.up,                          endT.position * 5 * Vector.up,                         Color.red,                          null,                         width);     } }
94362
I am making a game in Unity 5 in C# and I need to make the terrain infinite. I have tried to make it infinite but it just keeps spawning the terrain too much times and then the game crashes. Does someone know how I can make the terrain infinite? Here is my  code.  using System.Collections; using System.Collections.Generic; using UnityEngine;  public class TerrainScript : MonoBehaviour {     public Transform PlayerTransform;     private float SpawnZ = 4139f;     public GameObject[] prefabs;     private float RoadLength = 2.2f;     private int amountRoads = 6;     private List&lt;GameObject&gt; roadList;      public void Start()     {         roadList = new List&lt;GameObject&gt;();     }     public void Update()     {         if(PlayerTransform.position.z &gt; (SpawnZ - amountRoads * RoadLength))         {             spawnTile(0);         }     }      public void spawnTile(int index)     {         GameObject go;         go = Instantiate(prefabs[index]) as GameObject;         go.transform.SetParent(transform);         go.transform.position = Vector3.forward * SpawnZ;         SpawnZ += RoadLength;     } }
34351
As picture depicted my camera moving on path i want to lookAt bath different object smoothly. Currently have tried  trasnform.LooAt(activePath.gameObject.transform);   but it producing jerky result. object suddenly lookAt to next object how to avoid it. I searched and found this sloution but it also not working  var targetRotation = Quaternion.LookRotation(activePath.gameObject.transform.position - transform.position);         transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime);
8346
Why is the unity feedback system used? This block diagram is for a 2 DOF ball balancing using a PID controller.
12446
With the help of the Stack Overflow community I've written a pretty basic-but fun physics simulator.    You click and drag the mouse to launch a ball.  It will bounce around and eventually stop on the "floor".  My next big feature I want to add in is ball to ball collision.  The ball's movement is broken up into a x and y speed vector.  I have gravity (small reduction of the y vector each step), I have friction (small reduction of both vectors each collision with a wall). The balls honestly move around in a surprisingly realistic way.  I guess my question has two parts:   What is the best method to detect ball to ball collision? Do I just have an O(n^2) loop that iterates over each ball and checks every other ball to see if it's radius overlaps? What equations do I use to handle the ball to ball collisions? Physics 101 How does it effect the two balls speed x/y vectors?  What is the resulting direction the two balls head off in?  How do I apply this to each ball?     Handling the collision detection of the "walls" and the resulting vector changes were easy but I see more complications with ball-ball collisions.  With walls I simply had to take the negative of the appropriate x or y vector and off it would go in the correct direction.  With balls I don't think it is that way.  Some quick clarifications: for simplicity I'm ok with a perfectly elastic collision for now, also all my balls have the same mass right now, but I might change that in the future.    Edit: Resources I have found useful  2d Ball physics with vectors:  2d Ball collision detection example:     Success!  I have the ball collision detection and response working great!  Relevant code:  Collision Detection:  for (int i = 0; i &lt; ballCount; i++)   {       for (int j = i + 1; j &lt; ballCount; j++)       {           if (balls[i].colliding(balls[j]))           {             balls[i].resolveCollision(balls[j]);         }     } }   This will check for collisions between every ball but skip redundant checks (if you have to check if ball 1 collides with ball 2 then you don't need to check if ball 2 collides with ball 1.  Also, it skips checking for collisions with itself).  Then, in my ball class I have my colliding() and resolveCollision() methods:  public boolean colliding(Ball ball) {     float xd = position.getX() - ball.position.getX();     float yd = position.getY() - ball.position.getY();      float sumRadius = getRadius() + ball.getRadius();     float sqrRadius = sumRadius * sumRadius;      float distSqr = (xd * xd) + (yd * yd);      if (distSqr &lt;= sqrRadius)     {         return true;     }      return false; }  public void resolveCollision(Ball ball) {     // get the mtd     Vector2d delta = (position.subtract(ball.position));     float d = delta.getLength();     // minimum translation distance to push balls apart after intersecting     Vector2d mtd = delta.multiply(((getRadius() + ball.getRadius())-d)/d);        // resolve intersection --     // inverse mass quantities     float im1 = 1 / getMass();      float im2 = 1 / ball.getMass();      // push-pull them apart based off their mass     position = position.add(mtd.multiply(im1 / (im1 + im2)));     ball.position = ball.position.subtract(mtd.multiply(im2 / (im1 + im2)));      // impact speed     Vector2d v = (this.velocity.subtract(ball.velocity));     float vn = v.dot(mtd.normalize());      // sphere intersecting but moving away from each other already     if (vn &gt; 0.0f) return;      // collision impulse     float i = (-(1.0f + Constants.restitution) * vn) / (im1 + im2);     Vector2d impulse = mtd.normalize().multiply(i);      // change in momentum     this.velocity = this.velocity.add(impulse.multiply(im1));     ball.velocity = ball.velocity.subtract(impulse.multiply(im2));  }   Source Code:     If anyone has some suggestions for how to improve this basic physics simulator let me know!  One thing I have yet to add is angular momentum so the balls will roll more realistically.  Any other suggestions?  Leave a comment!
65543
This is a simple component, not sure what I am missing, this is exactly referred in the docs:   Component:  &lt;aura:component &gt;     &lt;aura:handler name="init" action="{!c.navigate}" value="this"/&gt; &lt;/aura:component&gt;   JSController:  ({     navigate : function(component, event, helper) {         var urlEvent = $A.get("e.force:navigateToURL");         urlEvent.setParams({             "url": 'https://www.google.com/maps/place/'         });         urlEvent.fire();     } })   Error:  This page has an error. You might just need to refresh it. Action failed: c:navigatetoURlcmp$controller$navigate [Cannot read property 'setParams' of undefined] Failing descriptor: {c:navigatetoURlcmp$controller$navigate}
12697
I selected a single face in the object (car wheel, see picture) to be given a particular material (rubber, red color). However, when I press "assign" in the material tab, the whole object (wheel) is painted in the material. How can I limit this to the face?
16308
Some shots I see online I don't understand how the tracking is done.      The car is coming at the camera while the motion blur is also towards the camera, so if you move your camera in the direction of the motion you will also blur the car. I guess these photos are a complete photoshop job?
98755
How can I limit the position of a rigidbody, between two values ​​if I use this code:  public Vector3 dir;  Rigidbody rb;  void Awake() {     rb = GetComponent&lt;Rigidbody&gt;(); }  void FixedUpdate() {     rb.velocity = new Vector3(0f, 0f, 6f);      rb.AddForce(dir * 1f, ForceMode.VelocityChange); }   If I use Vector3.Clamp then the object will shake
36589
I am making a mobile VR project in Unity, and I have a 360-degree video that starts playing where I can look around using a VR headset.  I am trying to set the start rotation of the video to the same rotation as my phone. So no matter where I look when I start the video, that should be my start rotation. I used Input.gyro.attitude in the start but that did not fix my problem. I think I am using it wrong.  This is my code (on the camera inside the sphere):  using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;  public class Gyroscope : MonoBehaviour {     private bool gyroEnabled;     private Gyroscope gyro;     private GameObject cameraContainer; //A camera container for my main camera     private GameObject videoSphere; //The sphere my video is in     private Quaternion rot;      private void Start()     {         videoSphere = GameObject.FindGameObjectWithTag("Video");         cameraContainer = new GameObject("Camera Container");          gyroEnabled = EnableGyro();          cameraContainer.transform.position = transform.position; // put the cameracontainer into the sphere         cameraContainer.transform.rotation = Input.gyro.attitude; // here I want to set the cameracontainer to the rotation of my phones gyroscope          transform.SetParent(cameraContainer.transform); // make my main camera a child of the camera Container          videoSphere.transform.localRotation = cameraContainer.transform.rotation; // Here I wanted to set my sphere rotation to the camera rotation         Debug.Log(videoSphere.transform.localRotation);     }      private bool EnableGyro()     {         if (SystemInfo.supportsGyroscope)         {             Input.gyro.enabled = true; // turn on my gyroscope              cameraContainer.transform.rotation = new Quaternion(0, 90, -90, 0); // rotate my camera container so the video shows good             rot = new Quaternion(0, 0, 1, 0); // set the variable rot so that you can turn your device             return true;         }         return false;     }      private void Update()     {         if (gyroEnabled)         {             transform.localRotation = Input.gyro.attitude * rot; //this makes you turn the device and it recognizes the input of the phones gyroscope                 }     } }
112025
I am trying to spawn one gameobject from a list of gameobjects each time I touch the trigger with the controller.  But when I do this, all the game objects from the list spawn together at the same time. I couldn't figure out how to solve this problem and make them spawn one at a time instead, where the next touch spawns the next object in the list, and so on.    using System.Collections; using System.Collections.Generic; using UnityEngine;  public class Trigger : MonoBehaviour {      public Transform spawnPoint;     //public GameObject Prefab;     public List&lt;GameObject&gt; items = new List&lt;GameObject&gt;();      void OnTriggerEnter(Collider other)     {         //GameObject Prefab = new GameObject("prefab");          for (int i = 0; i &lt; items.Count; i++)         {             Instantiate(items[i], spawnPoint.position, spawnPoint.rotation);             Debug.Log("Hello World" +i);         }      }  }
72121
I created a controller which looks like this  public with sharing class EventRegistrationController {      // A CONTROLLER FUNCTION     // FUNCTION RETURNS A LIST OF cSession      public List&lt;cSession&gt; getSessions() {            //DO STUFF       }     //A PUBLIC CLASS WITHIN CONTROLLER    @TestVisible public class cSession      {         public Session__c con {get; set;}         public Boolean selected {get; set;}          //This is the contructor method.          public cSession(Session__c c) {              con = c;             selected = false;         }     }  }   I need to write a test code for the controller, how can I create a list of cSession and call getSession function?
86697
I bought a book called Programming game AI by example and I am trying to implement the arrive steering behavior. The problem I am having is that my objects oscillate around the target position; after oscillating less and less for awhile they finally come to a stop at the target position. Does anyone have any idea why this oscillating behavior occur? Since the examples accompanying the book are written in C++ I had to rewrite the code into C#. Below is the relevant parts of the steering behavior:  private enum Deceleration {     Fast = 1,     Normal = 2,     Slow = 3 }  public MovingEntity Entity { get; private set; }  public Vector2 SteeringForce { get; private set; }  public Vector2 Target { get; set; }  public Vector2 Calculate() {     SteeringForce.Zero();      SteeringForce = SumForces();      SteeringForce.Truncate(Entity.MaxForce);      return SteeringForce; }  private Vector2 SumForces() {     Vector2 force = new Vector2();      if (Activated(BehaviorTypes.Arrive))     {         force += Arrive(Target, Deceleration.Slow);          if (!AccumulateForce(force))             return SteeringForce;     }      return SteeringForce; }  private Vector2 Arrive(Vector2 target, Deceleration deceleration) {     Vector2 toTarget = target - Entity.Position;      double distance = toTarget.Length();      if (distance &gt; 0)     {         //because Deceleration is enumerated as an int, this value is required         //to provide fine tweaking of the deceleration..         double decelerationTweaker = 0.3;          double speed = distance / ((double)deceleration * decelerationTweaker);          speed = Math.Min(speed, Entity.MaxSpeed);          Vector2 desiredVelocity = toTarget * speed / distance;          return desiredVelocity - Entity.Velocity;     }      return new Vector2(); }  private bool AccumulateForce(Vector2 forceToAdd) {     double magnitudeRemaining = Entity.MaxForce - SteeringForce.Length();      if (magnitudeRemaining &lt;= 0)         return false;      double magnitudeToAdd = forceToAdd.Length();      if (magnitudeToAdd &gt; magnitudeRemaining)         magnitudeToAdd = magnitudeRemaining;      SteeringForce += Vector2.NormalizeRet(forceToAdd) * magnitudeToAdd;      return true; }   This is the update method of my objects:  public void Update(double deltaTime) {     Vector2 steeringForce = Steering.Calculate();      Vector2 acceleration = steeringForce / Mass;      Velocity = Velocity + acceleration * deltaTime;      Velocity.Truncate(MaxSpeed);      Position = Position + Velocity * deltaTime; }   If you want to see the problem with your own eyes you can download a minimal example .  Thanks in advance.
88016
I've spent more time than I should trying to get my ray picking program working. I'm pretty convinced my math is solid with respect to line plane intersection, but I believe the problem lies with the changing of the mouse screen touch into 3D world space.  Heres my code:      public void passTouchEvents(MotionEvent e){           int[] viewport = {0,0,viewportWidth,viewportHeight};         float x = e.getX(), y = viewportHeight - e.getY();          float[] pos1 = new float[4];         float[] pos2 = new float[4];         GLU.gluUnProject(   x, y, 0.0f,                             mViewMatrix, 0,                             mProjectionMatrix, 0,                             viewport, 0,                             pos1, 0);           GLU.gluUnProject(   x, y, 1.0f,                             mViewMatrix, 0,                             mProjectionMatrix, 0,                             viewport, 0,                             pos2, 0);     }   Just as a reference I've tried transforming the coordinates 0,0,0 and got an offset.  It would be appreciated if you would answer using OpenGL ES 2.0 code.
23987
How come pathfinder - minus front is not working? I want a stylized N where that white part is taken out