Search Unity

Help with collisions

Discussion in 'World Building' started by krickey, May 6, 2021.

  1. krickey

    krickey

    Joined:
    May 6, 2021
    Posts:
    4
    Im trying to make a top down game but the tutorial series im following's movement script didnt work so i made my own, and now, im here in the unity forums asking for help, anyways how do i make my player have collisions if it's movement script is this

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerMovement : MonoBehaviour
    {
    public float moveSpeed = 5f;
    public Rigidbody2D rb;
    Vector2 movement;
    public Animator animator;

    void Update()
    {
    // Input

    movement.x = Input.GetAxisRaw("Horizontal");
    movement.y = Input.GetAxisRaw("Vertical");

    animator.SetFloat("MoveX", movement.x);
    animator.SetFloat("MoveY", movement.y);
    animator.SetFloat("Speed", movement.sqrMagnitude);
    }

    void FixedUpdate()
    {
    // Movement

    rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
    }
    }

    please help as it would mean a lot, a little info is that im trying to give collisions to a layer called Solid Objects.