c# - Monogame collision bug -


i began create platformer monogame , c# , got strange bug ground collision. made block , player, both use bounding collisions this:

public rectangle collision {     => new rectangle((int)_pos.x, (int)_pos.y, _w, _h); } //only player entity public rectangle groundcollision {     => new rectangle((int)_pos.x, (int)_pos.y+_w, _w, 1); } 

it works good, though space appears space ply , ground so:

this.

both block , player textures white, distance in 1 pix visible. after jumps (sometimes movement) may fix it, though after began hover again. here player update code:

public void update() {     if (_movable)     {         vector2 oldpos = _pos;         _pos += new vector2(_vel, -_acc);         if(_pos.y >= 96)         {             bool c = collides;         }         if (grounded)         {             _pos += new vector2(0, _acc);             _acc = 0;         }         /*if (collides)         {             _pos = oldpos;         }*/     } }  //entity methods protected void _move(float dir, float delta) {     _vel = (float) _speed * dir * delta; }  protected void _gravity(float delta) {     float fallspeed = (float) math.round(phys.gravity * delta * -5f);     if (_acc - fallspeed >= 0)         _acc = fallspeed;     else if (_acc >= 0)         _acc = 0; }  protected void _jump(float delta) {     _acc += _jumpforce * delta * 10f; } 

so, there ways fix this?


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -