Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nurn2 committed Oct 30, 2024
1 parent 534611f commit 709eafd
Show file tree
Hide file tree
Showing 46 changed files with 5,889 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .vsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Workload.ManagedGame"
]
}
55 changes: 55 additions & 0 deletions Assets/CharControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharControl : MonoBehaviour
{
[SerializeField]
float speed;
[SerializeField]
float jumpForce;
[SerializeField]

bool isGrounded;
public RaycastHit2D hit;
public float distance;
Rigidbody2D myRigidBody2D;

// Start is called before the first frame update
void Start()
{
myRigidBody2D = GetComponent<Rigidbody2D>();
isGrounded = false;
}

// Update is called once per frame
void Update()
{
myRigidBody2D.AddForce(new Vector2(Input.GetAxis("Horizontal")*speed, 0f));

if(Input.GetButtonDown("Fire1") && isGrounded == true)
{
myRigidBody2D.AddForce(new Vector2(0f,5f)*jumpForce, ForceMode2D.Impulse);
}


//hit = Physics2D.Raycast(transform.position, Vector2.down, 0.6f);

// If it hits something...
if (Physics2D.Raycast(transform.position, Vector2.down, 0.6f))
{
// Calculate the distance from the surface and the "error" relative
// to the floating height.
distance = Mathf.Abs(hit.point.y - transform.position.y);
if (distance >= 0.6f)
{
isGrounded = true;
}
else
{
isGrounded = false;
}
}
}

}
11 changes: 11 additions & 0 deletions Assets/CharControl.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/LAB1-SPRITE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 709eafd

Please sign in to comment.