• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By wobbegong_
      I am taking an absolute beginner's game development course and we have just finished game jams in small groups. Our current assignment is to get feedback from people working in any aspect of game development. I would very much appreciate any feedback! The game is up on itchi.io (sound warning) https://wobbegong.itch.io/zombie-shooter It's essentially a very basic PvE.
      I also have some things I'm wondering about, but you don't necessarily have to answer these. 
      1. Do you have any tips on working with physics? My group wrestled a bit with Rigidbody physics not totally working the way we wanted to -- jumping ended up kind of floaty and inclines seem to mess up movement. Alternatively... how can I build terrains with depth that won't result in wonky physics?
      2. How can I keep up the level of challenge in an interesting way as the player progresses through the waves?
      3. What are some of your personal guidelines for creating title screens?
      Thank you very much in advance!
    • By ethancodes
      I'm having a weird issue with detecting a collision. I've tried everything I could find online but nothing seems to work. I have a brick object. It has a 2D Collider attached and I have also attached a 2D Rigidbody on it. I also have an EndScreen 2D Collider. The EndScreen 2D collider is tagged with "EndScreen". I am trying to detect when a brick collides with the end screen collider and simply print "game over" in the console. 
      This is my current code for this part of the program, it is attached to the bricks:
      void OnCollisionEnter (Collision2D collision) { if (collision.gameObject.tag == "EndScreen") { Debug.Log("Game over"); } } Several things have happened depending on the set up. If I have the rigidbody 2D set as static, my ball object can still collide with the bricks, but I get no Log message. If I set it to Kinematic or Dynamic, I get absolutely no interaction between the ball and the bricks, and nothing when the bricks pass through the collider. I have tried to set the collider to a trigger and use OnTriggerEnter2D, no change. I have tried to put the rigidbody on the EndScreen object and tried to set it's body type to all 3 settings, no change. The only thing I can think of that I have not done is put the script on the EndScreen object and switch the tag to the bricks. The reason I have not done this is because I will have several types of bricks, some of which will have different tags. 
       
      Please tell me somebody can see what I'm doing wrong here, because I'm losing my mind over something I feel should be ridiculously simple. Thanks.
    • By Sandman Academy
      Downloadable at:
      https://virva.itch.io/sandman-academy
      https://gamejolt.com/games/sandmanacademy/329088
      https://www.indiexpo.net/en/games/sandman-academy
      https://www.gamefront.com/@sandmanacademy
      http://www.indiedb.com/games/sandman-academy
    • By Sandman Academy
      Downloadable at:
      https://virva.itch.io/sandman-academy
      https://gamejolt.com/games/sandmanacademy/329088
      https://www.indiexpo.net/en/games/sandman-academy
      https://www.gamefront.com/@sandmanacademy
      http://www.indiedb.com/games/sandman-academy
    • By Sandman Academy
      Downloadable at:
      https://virva.itch.io/sandman-academy
      https://gamejolt.com/games/sandmanacademy/329088
      https://www.indiexpo.net/en/games/sandman-academy
      https://www.gamefront.com/@sandmanacademy
      http://www.indiedb.com/games/sandman-academy
  • Advertisement
  • Advertisement
Sign in to follow this  

Unity How To Fix/Create Movement Code In Unity

This topic is 878 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey,

I've been working on a movement system in Unity, and have a functional one. I wouldn't say the code is any good, though...It's all in one method, and I've got no idea how to move it to other functions. I've tried, and it's all ended with the player glitching out in mid-air and not moving. Can any of you share your movement code used in Unity? I would like to use rigidbodies, and only need WASD movement (Along with holding shift to increase movement speed). The game is 3D.

Code: http://pastebin.com/rR8wduPn

 

I'd appreciate some help.

Share this post


Link to post
Share on other sites
Advertisement

Standard assets has a Character Controller. Standard Assets > Characters > First Person Character Controller. I think there's a 3rd person one as well. That's the best place to start if you need a generic one. There wasn't a sprint option last time i checked , but that's like a 5 line script.

 

If you want to code your own, just attach the camera to a object with a rigid body and a collider and tie your keys to AddForce.

 

For example - to move forward use something like:

 

float speed = 5f ;

if( Input.GetAxis("Vertical")>0){ transform.GetComponent<Rigidbody>().AddForce( Vector3.forward * speed , ForceMode.Acceleration ) ;}

 

and do the same, except check if Input.GetAxis < 0 to move backwards and check GetAxis("Horizontal") to move left and right.

 

I didn't test that, but it should work. Might have to tweak speed though and maybe tie it to Time.deltaTime. Also, calling GetComponent every frame is kind of costly, so it's better to define it during Start().

Share this post


Link to post
Share on other sites


I would like to use rigidbodies

Is there a particular reason you want to use rigidbodies? I've built character controllers both ways, and I have to say, the versions without a rigidbody are way simpler, and a lot more stable in practice. Rigidbodies have all sorts of weird behavior around collisions and friction that you are going to have to work around.

Share this post


Link to post
Share on other sites

 


I would like to use rigidbodies

Is there a particular reason you want to use rigidbodies? I've built character controllers both ways, and I have to say, the versions without a rigidbody are way simpler, and a lot more stable in practice. Rigidbodies have all sorts of weird behavior around collisions and friction that you are going to have to work around.

 

 

That may be my fault. I was talking to him before and didn't understand that a controller could replace a RB. I need to do more research on the controller component. My bad.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement