I’m dabbling in making some games in unity to learn the ropes so I can work on a single project eventually and make it good enough for my standards (if it’s foolish the expect that or not is another subject)
anyway I’m making a 2d platformer now, and I have a very specific feeling in mind for the movement. I attempted to implement it myself and succeeded, with drag and gravity and all that, but I had trouble with implementing collisions. I used a raycast to check if the player is grounded and just set my velocity var to 0 when it’s grounded, but sometimes it’d just phase through the ground and get stuck in the middle, sometimes it’d phase completely through, and it just wasn’t consistent.
because I want my character to be completely moved by my implementation of movement, I made it kinematic because that’s from what I’ve heard is the most fit for movement that’s largely defined by code, but I wanted to hijack the collision functionality of the physics simulation while ignoring the other parts, but when I let my object fall onto a static rigidbody, it completely ignored the collision (I did turn on “use full kinematic contact”), not affecting the velocity at all
sorry for the story behind it I just wanted to get my cause across. basically I want to define all of the movement of the body on my own through code, but I want it to still respect collisions to not allow it to pass through ground. if there’s a better solution, like using dynamic bodies or working on my own full collision system, I’d like to hear them.
here’s the code I made in another project to try and get to the bottom of why it wasn’t working
it’s not much but that’s what it is
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movementtest : MonoBehaviour
{
Rigidbody2D rb;
public float maxSpeed = 10f;
public float accel = 1f;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
if (rb.velocity.y < maxSpeed){
rb.velocity += Vector2.down * accel * Time.fixedDeltaTime;
}
}
}
if I misunderstood the use of kinematic or something like that, I’d be happy to learn. as a last line to make sure my goal is clear; I want to define the movement of the body completely on my own, apart from 1 part: collision. I want the body to respect collisions as in not clip through other colliders, but still retain only my definitions for movement. I have a feeling that I’m missing a very big part of the picture so enlighten me