Brutile Posted December 14, 2016 Share Posted December 14, 2016 I decided to make a mini golf game for the game tournament, but I'm being haunted by some physics bug. I have a ball that is 0.1 scale and after it gets hit, once it gets to a specific point, it falls throught the floor. It happens without fail. The hotspot seems to be in the middle of the CSG where the two triangles meet. Even when I scale the ball to 1, it doesn't fall through the floor, but it does hit a bump and put it off course. Here's my script in case you can see anything that might be wrong. Script.mouseSensitivity = 2.0 Script.camOffset = Vec3(0, 1, -3) Script.camSmoothing = 10.0 Script.hitForce = 350 function Script:Start() --initialize camera self.camera = Camera:Create() self.camera:SetFOV(70) self.camera:SetRange(0.05, 1000) self.camera:SetMultisampleMode((System:GetProperty("multisample", "4"))) self.camera:SetRotation(self.entity:GetRotation(true)) self.camera:SetPosition(self.entity:GetPosition(true) + self.camOffset) --add listener as camera self.listener = Listener:Create(self.camera) --create player model self.entity:SetPosition(self.entity:GetPosition(true) + Vec3(0, 0.1, 0), true) self.model = Model:Sphere() self.model:SetScale(0.1, 0.1, 0.1) self.model:SetPosition(self.entity:GetPosition(true), true) self.model:SetParent(self.entity) self.model:SetColor(1,1,1) --setup ball physics self.entity:SetMass(1) self.entity:SetFriction(0.1, 0.1) self.entity:SetSweptCollisionMode(true) --Create a shape local shape = Shape:Sphere(0,0,0, 0,0,0, 0.1,0.1,0.1) self.entity:SetShape(shape) shape:Release() --set collision type of player self.entity:SetCollisionType(Collision.Prop) local window = Window:GetCurrent() local context = Context:GetCurrent() window:SetMousePosition(Math:Round(context:GetWidth() / 2), Math:Round(context:GetHeight() / 2)) self.mouseDifference = Vec3(0, 0, 0) self.camRotation = Vec3(0, 0, 0) self.camera:SetRotation(self.camRotation) end function Script:UpdateWorld() local window = Window:GetCurrent() local context = Context:GetCurrent() --mouse look self.currentMousePos = window:GetMousePosition() window:SetMousePosition(Math:Round(context:GetWidth() / 2), Math:Round(context:GetHeight() / 2)) self.currentMousePos.x = Math:Round(self.currentMousePos.x) self.currentMousePos.y = Math:Round(self.currentMousePos.y) self.mouseDifference.x = Math:Curve(self.currentMousePos.x - Math:Round(context:GetWidth() / 2), self.mouseDifference.x, 3) self.mouseDifference.y = Math:Curve(self.currentMousePos.y - Math:Round(context:GetHeight() / 2), self.mouseDifference.y, 3) self.camRotation.x = Math:Clamp(self.camRotation.x + self.mouseDifference.y / self.mouseSensitivity, 0, 70) self.camRotation.y = self.camRotation.y + (self.mouseDifference.x / self.mouseSensitivity) --camera orbit around ball self.camera:SetRotation(self.camRotation) self.camera:SetPosition(self.entity:GetPosition(true), true) self.camera:Move(self.camOffset) --hit the ball if window:MouseHit(1) then local c = self.camera:GetPosition(true) local p = self.entity:GetPosition(true) local dir = p - Vec3(c.x, p.y, c.z) dir = dir:Normalize() * self.hitForce self.entity:AddForce(dir) end end All I did was create a new map, added a pivot at 0,0,0 with this script assigned, then created a CSG cube at pos: 0, -16, 2688 and size: 512cm, 32cm, 5888cm. Hit the ball without moving the mouse and it will get half way down and fall through. I even tried a small 512x512 floor with walls and just hit it around. Eventually it would fall through. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted December 14, 2016 Share Posted December 14, 2016 Thats sound like same issue I was having when I made my minigolf game couple years ago. Physics accuracy for the ball were attrocious. After a lot of fumbling about I gave up. The ball seemed to be filled with water or something, it would roll straight for a while and then all of the sudden it would roll in to a different direction. This mostly happened when slowing down. Things to try (which some of you already have): Swept collision on ball and level geometry Setting a higher physics resolver interval instead of a csg sphere, using a model with a different physics shapes, going from relatively basic, to extreme high polycount (for a ball). Larger model/csg sphere instead of the tiny scale you are using now. 1 Quote Link to comment Share on other sites More sharing options...
Brutile Posted December 14, 2016 Author Share Posted December 14, 2016 Thanks, I'll try those Quote Link to comment Share on other sites More sharing options...
Brutile Posted December 14, 2016 Author Share Posted December 14, 2016 Unfortunately, those didn't work. I'm convinced there's a correlation between the ball falling through and the seam where the two trianges meet to create the polygon of the surface. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted December 14, 2016 Share Posted December 14, 2016 You can experiment with the hollow csg brush function to get more triangles accross the surface. Then you will start to see even more inaccuracies. Quote Link to comment Share on other sites More sharing options...
Brutile Posted December 14, 2016 Author Share Posted December 14, 2016 Yep. Put a whole bunch of smaller boxes and it's like one of those car testing tracks (but flat). The ball just gets stuck on them. Quote Link to comment Share on other sites More sharing options...
Josh Posted December 14, 2016 Share Posted December 14, 2016 It is possible you might get better results with a larger ball. You would need to make everything in your level larger, of course. I would like to see a demo of this in action. Jorn, without having the framerate displayed it is difficult to tell what is happening there. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Brutile Posted December 15, 2016 Author Share Posted December 15, 2016 I recorded a short demo of what is happening. I also enabled wireframe so you can see what I mean about the seam between the triangles. Quote Link to comment Share on other sites More sharing options...
Josh Posted December 15, 2016 Share Posted December 15, 2016 I actually do think I know how this can be improved. 2 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.