Collision resolving not behaving as expected

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Collision resolving not behaving as expected

Post by Gunroar:Cannon() »

The movement isn't working as expected.

The friction between the player and the floor is really low, so when the player moves it should move crazy fast, both against a wall verticaly and when it moves horizontally.
But the player moves normally horizontally and only moves crazy fast vertically when it moves against a wall (even if it has no y velocity it gains some by just bumping into the wall).

Why does the friction/collision resolution not work as it should?
I'm stumped.

Code for resolving of collision
toybox/entites/Object.lua
~line 312

Code: Select all

function Object:__resolve_collision(instance, trash_separation_x, trash_separation_y, collision)
  --collision is collision data gotten from kikito's bump.lua
  
  local friction = instance.friction
  
  local normalX, normalY = collision.normal.x, collision.normal.y
  local tangentX, tangentY = -normalX, normalY
  -- relative velocity
  local vx = self.vx - (instance.vx or 0)
  local vy = self.vy - (instance.vy or 0)

  -- penetration speed
  local penetration_speed = vx * normalX + vy * normalY

  -- penetration component
  local penetration_x = normalX * penetration_speed
  local penetration_y = normalY * penetration_speed

  -- tangent component
  local tangent_x = vx - penetration_x 
  local tangent_y = vy - penetration_y

  -- restitution
  local restitution = 1 + math.max(self.bounce, instance.bounce or 0)

  -- friction
  local friction = math.max(self.friction, instance.friction or 0)
  
  -- change the velocity of shape a
   
  self.vx = vx - penetration_x * restitution + tangent_x * friction
  
  self.vy = vy - penetration_y * restitution + tangent_y * friction
end
Was coded on a touchscreen device but should work with keyboards too.
(kind of based of this)

But flip it, life's handing you lemons, make lemonade then Image
Attachments
lovegame.love
(63.9 KiB) Downloaded 164 times
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
Post Reply

Who is online

Users browsing this forum: No registered users and 38 guests