Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Trying to move a character using addforce

$
0
0
I am trying to make a 2d game for fun, but I ran into a problem. This is the script I am using to move and jump. When I try to move it doesn't do anything. I debugged the Vector2 move and it seems to be fine. I don't know what is happening. Can someone please help me? Script: using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovement : MonoBehaviour { public Rigidbody2D rb; public float runSpeed; public float jumpForce; bool isGrounded = true; Vector2 jump; Vector3 move; void Start () { jump = new Vector2(0, 1f); } // Update is called once per frame void Update () { float moveHorizontal = Input.GetAxis("Horizontal") * runSpeed; move = new Vector3(moveHorizontal, 0); } private void OnCollisionEnter2D() { isGrounded = true; } void FixedUpdate () { //transform.Translate(move * Time.fixedDeltaTime); rb.AddForce(move, ForceMode2D.Force); if (Input.GetButtonDown("Jump") && isGrounded) { rb.AddForce(jump * jumpForce, ForceMode2D.Impulse); isGrounded = false; } } } this is a link to the player inpector. /storage/temp/127704-screenshot-3.png

Viewing all articles
Browse latest Browse all 1264


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>