I'm making a competitive 2-player 2D racing game for a school project. I'm struggling with the movements of my car: I made it a square for testing purposes and it can move left, right, up or down, but it can't make smooth turns around corners.  How can I make my car (currently a square) make smooth movements? I've heard vectors might help, but I don't know how to use them.  I'm writing this in C# with Visual Studio.    My car control code looks like this right now:  private void Form1_KeyDown(object sender, KeyEventArgs key) {     // player1 controls     if (key.KeyCode == Keys.Up)     { Player1.Top -= 5; }     if (key.KeyCode == Keys.Down)   { Player1.Top += 5; }      if (key.KeyCode == Keys.Left)   { Player1.Left -= 5; }     if (key.KeyCode == Keys.Right)  { Player1.Left += 5; }      // player2 controls     if (key.KeyCode == Keys.W) { Player2.Top -= 5; }     if (key.KeyCode == Keys.S) { Player2.Top += 5; }      if (key.KeyCode == Keys.A) { Player2.Left -= 5; }     if (key.KeyCode == Keys.D) { Player2.Left += 5; } }
122119
I have goggled how to do this and found this  I have had a go at it but most of the functions that were showed didn't work I just got errors because they didn't exist. I have looked at the cos and sin functions but don't understand how to use them or how to get the car movement working correctly using vectors. I have no code because I am not sure what to do sorry.  Any help is appreciated.   EDIT:  I have restrictions that I must use the TL engine for my game, I am not allowed to add any sort of physics engine. It must be programmed in c++. Here is a sample of what i got from trying to follow what was done in the link I provided.  if(myEngine-&gt;KeyHeld(Key_W))     {         length += carSpeedIncrement;     }     if(myEngine-&gt;KeyHeld(Key_S))     {         length -= carSpeedIncrement;     }     if(myEngine-&gt;KeyHeld(Key_A))     {         angle -= carSpeedIncrement;     }     if(myEngine-&gt;KeyHeld(Key_D))     {         angle += carSpeedIncrement;     }      carVolocityX = cos(angle);     carVolocityZ = cos(angle);      car-&gt;MoveX(carVolocityX * frameTime);     car-&gt;MoveZ(carVolocityZ * frameTime);
81948
For my banked road I sort of managed to make it look like it is a racing track.  I am really stuck with the pink part that is completely flat. I have a road texture and want to apply it to that, so that it follows the road   I think it should be easy but I don't know how to do it. I have searched but can't seem to find the right tutorial for this.
34378
I have a 3rd person camera which can rotate around the player. My problem is that wherever camera is facing, players forward is always the same direction.  For example when camera is facing the right side of the player, when I press button to move forward, I want player to turn to the left and make that the "new forward".  My camera script so far:  using UnityEngine; using System.Collections;  public class PlayerScript : MonoBehaviour {     public float RotateSpeed = 150,     MoveSpeed = 50;     float DeltaTime;      void Update()     {         DeltaTime = Time.deltaTime;         transform.Rotate(0, Input.GetAxis("LeftX") * RotateSpeed * DeltaTime, 0);         transform.Translate(0, 0, -Input.GetAxis("LeftY") * MoveSpeed * DeltaTime);     } }  public class CameraScript : MonoBehaviour {     public GameObject Target;     public float RotateSpeed = 170,     FollowDistance = 20,     FollowHeight = 10;     float RotateSpeedPerTime,     DesiredRotationAngle,     DesiredHeight,     CurrentRotationAngle,     CurrentHeight,     Yaw,     Pitch;     Quaternion CurrentRotation;      void LateUpdate()     {         RotateSpeedPerTime = RotateSpeed * Time.deltaTime;          DesiredRotationAngle = Target.transform.eulerAngles.y;         DesiredHeight = Target.transform.position.y + FollowHeight;         CurrentRotationAngle = transform.eulerAngles.y;         CurrentHeight = transform.position.y;          CurrentRotationAngle = Mathf.LerpAngle(CurrentRotationAngle, DesiredRotationAngle, 0);         CurrentHeight = Mathf.Lerp(CurrentHeight, DesiredHeight, 0);          CurrentRotation = Quaternion.Euler(0, CurrentRotationAngle, 0);         transform.position = Target.transform.position;         transform.position -= CurrentRotation * Vector3.forward * FollowDistance;         transform.position = new Vector3(transform.position.x, CurrentHeight, transform.position.z);          Yaw = Input.GetAxis("Right Horizontal") * RotateSpeedPerTime;         Pitch = Input.GetAxis("Right Vertical") * RotateSpeedPerTime;         transform.Translate(new Vector3(Yaw, -Pitch, 0));         transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z);          transform.LookAt(Target.transform);     } }
3895
How exactly does a  work?  This is an extremely broad question. What code keeps things bouncing against each other, what code makes the player walk into a wall instead of walk through the wall? How does the code constantly refresh the players position and objects position to keep gravity and collision working as it should?  If you don't know what a collision engine is, basically it's generally used in  to make the player acutally hit walls and the like. There's the 2D type and the 3D type, but they all accomplish the same thing: collision.  So, what keeps a collision engine ticking?
62875
I have a cube that has been scaled to be rectangular (controlled by a remote Raspberry Pi gyro/accelerometer/magnetometer) and am translating its orientation into Unity via calls to transform.localEulerAngles = new Vector3(...). This works wonderfully (the cube object modeled to be a Pi rotates perfectly), however now I'm running into issues with the actual physics.        Initially the ball will land on and roll around the Pi object, however when I start to increase the speed of my movements the ball will sometimes fall through the Pi.  The cube has a Rigidbody (no gravity, is kinematic) and Box collider (not triggered), and the sphere has a Rigidbody (has gravity, not kinematic) and Sphere collider (not triggered) attached.  I've tried varying the collision detection from discrete to continuous on both objects and have noticed similar behaviors.  The intent is to turn this into a marble maze type game, and the issue that I have is similar.  If I roll the ball into the joint between a wall and the floor (both stretched cubes), rotate it down, and then rotate it up, the ball will fall through the joint.  I have the same movement code attached to the GameArea object below.  Again, same issue with various types of collision detection applied.       My assumption is that this is a quickness of movement thing, as the cubes overlap each other (there's not a space for the ball to sneak through).  For reference, in the physics colliders section of the project preferences, all relevant layers are supposed to collide with each other.  I don't mind getting into code-based collision detection, but this seemed fairly trivial for Unity to take care of so I was wondering if I was missing something obvious.
1325
I have animation where object changes his shape using shape keys, and I want to make some animation smoothing with graph editor. Is there a way to use graph editor for shape key animation?
47735
I'm using Unity C#. How would I create the effect in my pool game, a line showing the direction of the second (not white) ball after collision.  Example:   I need to make the line coming from the ball (second/leftmost)  P.S. I made the other line by using Raycast to find the hit point and set that point last position of line renderer (white ball is a start position for line renderer and it casts the ray)
23254
So I'm making a basic car model here for fun, but when I try to add the subdivision surface modifier for smoother body, the side of the car become what it looks like in the screenshot. Is there any solution to make the side look less bulky? Any help is appreciated. :D
64866
I am implementing steering algorithms with group management for spaceships (fighters). I select a leader and assign the target positions for the other spaceships based on the target position of the leader and an offset. This works well. But when my spaceships arrive they all have a different direction. I want them to keep to look in the same direction (target - start).   I also want to combine this behavior with a minimum turning radius that is based on the speed. The only idea I have is to calculate a path for each spaceship with an point before the target position, so the ships have some time left to turn into the right position. But I dont know if this is a good idea. I guess there will be a lot of rare cases where this can cause a problem.  So the question is, if anybody knows how to solve this problem and has some (simple code) or pseudocode for me or at least some good explanation.
96267
I'd like to swap the controls for pan and orbit essentially so it's like AutoCAD where middle mouse click goes to pan and shift middle click is orbit. Where's the best place to suggest this as a feature add?
115456
From what I can tell the choice of car does not influence driving speed or handling and is mostly of aesthetic nature, but are all cars really completely equal when it comes to gameplay?   Some cars are bigger in height for example (like the van), does this provide a bigger area to hit the ball? Or are the hitboxes of all cars equal no matter which model is chosen? Are there any other differences between cars that could make a difference (as small as it may be) on the pitch?
119717
Dear Blender Community,   i would like to build a very simple carriage kind of vehicle, that is simply pushed or dragged over a surface and has the possibility to react to it. My first idea was to use the rigid body settings for it and just build it how i would build it in real life and push it with a cage like box over the surface. but whenever i start to push it, it simply explodes! I applied all the locations/sizes/transformations whatever and the objectcollision shapes are all set to "mesh". I realy don't get it and can't believe that it is so hard. Maybe someone has an idea how this kind of a model can work and react to an uneven surface, that there is this carriage vibe to it? Would be great!   this is how my model looks now, it doesn't need to be much more complex concerning the design:
31170
i am instantiating prefab cars ... the clones had a random countdown timer with each one off them and its working very well but the its not  decreasing its not counting down the timer is inside the spawn method the spawn method is inside the WHILE loop and the while loop is inside the UpDate() ... i  tried  to move the countdown to Update() but didnn't worked ... any ideas ...Thank You!  void Update() {     p -= Time.deltaTime;           while (carNumber &lt; cars &amp;&amp; p &lt;= 0 )         {              SpawnCars();             print(carNumber);             p = 5;                    }  }   and this is the spawn method:   public void SpawnCars() {     if (spawnAllowed)     {         // choose a random strat point 1/6              randomSpawnPoint = Random.Range(0, spawnPoints.Length);         // choose a random car 1/6         randomSpawnCars = Random.Range(0, Cars.Length);         // clone randomly a car(1/6) from a random pre_set-points(1/6)         GameObject obj = Instantiate(Cars[randomSpawnCars], spawnPoints[randomSpawnPoint].position, Quaternion.Euler(-90, 180, 0)) as GameObject;         // carNumber will count how many cloned car          carNumber++;         // destroy the  cloned car after N sec        // Destroy(obj, 8);         // every cloned car will take a tag with it         obj.gameObject.tag = "select" + k;         k++;         rcf = obj.GetComponent&lt;RayCastForward&gt;();         //textCDT         time = Random.Range(4f, time);         TextMesh txt = FindObjectOfType&lt;TextMesh&gt;();   //the Timer:         time -= Time.deltaTime;         coolDown = time.ToString("0");         txt.text = ""+coolDown;      } }   edit: i forgot to tell that the timer  is inside SpawnCars().
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;     } }
41917
I'm looking for some good references for learning how to model 2d physics in games. I am not looking for a library to do it for me - I want to think and learn, not blindly use someone else's work.  I've done a good bit of Googling, and while I've found a few tutorials on GameDev, etc., I find their tutorials hard to understand because they are either written poorly, or assume a level of mathematical understanding that I don't yet possess.  For specifics - I'm looking for how to model a top-down 2d game, sort of like a tank combat game - and I want to accurately model (among other things) acceleration and speed, heat buildup of 'components,' collisions between models and level boundaries, and missile-type weapons.  Websites, recommended books, blogs, code examples - all are welcome if they will aid understanding. I'm considering using C# and F# to build my game, so code examples in either of those languages would be great - but don't let language stop you from posting a good link. =)  Edit: I don't mean that I don't understand math - it's more the case that I don't know what I need to know in order to understand the systems involved, and don't really know how to find the resources that will teach me in an understandable way.
73898
I'm simply trying to make my character turn in his place, whether he's standing still or moving, currently, he isn't turning what-so-ever. Here is the code that I currently have for turning:  I AM NO LONGER USING THIS TURNING FUNTION vvv  void Turning() {     Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);     RaycastHit floorHit;      if (Physics.Raycast (camRay, out floorHit, camRayLength, floorMask))     {         Vector3 playerToMouse = floorHit.point - transform.position;         playerToMouse.y = 0f;          Quaternion newRotation = Quaternion.LookRotation(playerToMouse);         playerRigidbody.MoveRotation(newRotation);     } }   So what should be happening is my character should turn and face toward wherever my mouse is pointing, but that isn't happening and I'm not sure why.  Thank you in advance for any assistance.    WHAT I AM USING NOW  I have alternatively tried another bit of code which I will post below, I completely got rid of what is above in place of this:   Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); transform.LookAt(mousePos);   This will actually make the camera follow the mouse, but it goes crazy, the camera seems to spin in circles rapidly : here is actually a gif of what is happening.  Could anyone help me figure how how to fix it?
39063
I need to run some basic physics simulations on a headless machine and I'd like to program agent movements based on function outputs (e.g. "move left")-I have some code that programs WASD to move a cube that I'd like to modify such that it doesn't actually require me to press any keys but rather, if the program receives "Wkey" as an input (from another function) it's able to move the agent in the desired direction. Is this possible? (I also want to try to avoid using the logic editor to run the script if possible, any help on that would also be appreciated)    Current code below:   import bge   def main():      cont = bge.logic.getCurrentController()     own = cont.owner      keyboard = bge.logic.keyboard      wKey = bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.WKEY]     sKey = bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.SKEY]     aKey = bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.AKEY]     dKey = bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.DKEY]      if wKey:          own.applyMovement([0,0.2,0],True)      if sKey:          own.applyMovement([0,-0.2,0],True)      if aKey:          own.applyMovement([-0.2,0,0],True)      if dKey:          own.applyMovement([0.2,0,0],True)  main()