Question by
xwarflecx · Aug 01, 2018 at 02:29 AM ·
2dgameplatformersupport2d collision
Player Can walk through walls [2D]
btw, i am using tilemap collisions cause i made a tilemap, and for the player i have put a box collider and 2d rigidbody, heres my code:`using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Player : MonoBehaviour {
private float axisX;
private float axisY;
private Rigidbody2D rb;
public float jumpHeight;
public int speed;
// Use this for initialization
void Start () {
speed = 200;
jumpHeight = 300.0f;
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
axisX = Input.GetAxis("Horizontal");
transform.Translate(new Vector3(axisX, 0) * speed * Time.deltaTime);
if(Input.GetKeyDown(KeyCode.Space)) {
rb.velocity = new Vector3(0f, jumpHeight, 0f);
}
}
}
` someone please help .
Comment
Answer by xwarflecx · Aug 01, 2018 at 02:32 AM
heres some gifs too: https://gyazo.com/9c75c836d3ed69a7d34f393f476c6739
it would also be great if someone can help me with my jittery camera movement, heres the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public Transform target;
public float smoothTime = 0.15f;
Vector3 velocity = Vector3.zero;
public Vector3 offset;
void FixedUpdate(){
Vector3 targetPos = target.position;
transform.position = Vector3.SmoothDamp(transform.position + offset, targetPos, ref velocity, smoothTime);
}
}