Skrakle Posted March 1, 2015 Share Posted March 1, 2015 I have a moving model on my terrain, when it collides while climbing on what i sculped or another entity, they bounce back, how can i prevent from doing that? Thanks x=0;y=0;z=-20; camx=-5;camy=20;camz=-15; camrx=45;camry=15;camrz=0; function App:Start() --Initialize Steamworks (optional) Steamworks:Initialize() --Set the application title self.title="Test" --Create a window local windowstyle = window.Titlebar if System:GetProperty("fullscreen")=="1" then windowstyle=windowstyle+window.FullScreen end self.window=Window:Create(self.title,0,0,System:GetProperty("screenwidth","1280"),System:GetProperty("screenheight","720"),windowstyle) self.window:HideMouse() --Create the graphics context self.context=Context:Create(self.window,0) if self.context==nil then return false end --Create a world self.world=World:Create() self.world:SetLightQuality((System:GetProperty("lightquality","1"))) --Load a map local mapfile = System:GetProperty("map","Maps/test.map") if Map:Load(mapfile)==false then return false end self.model={} self.model[0] = Model:Load("testmodel.mdl") self.model[0]:SetScale(0.05); self.model[0]:SetPosition(x,y,z); self.model[0]:SetMass(1); self.model[0]:SetCollisionType(Collision.Prop); self.model[1] = Model:Load("testmodel.mdl") self.model[1]:SetScale(0.05); self.model[1]:SetPosition(x+15,y,z-15); self.model[1]:SetMass(1); self.model[1]:SetCollisionType(Collision.Prop); self.model[0]:SetShape(Shape:Box(6.81,48.805,-7.7830, 0,0,0, 49.809,98.074,42.164)) self.model[1]:SetShape(self.model[0]:GetShape()) self.camera = Camera:Create(); self.camera:SetPosition(camx+x,camy+y,camz+z); self.camera:SetRotation(camrx,camry,camrz); return true end function App:Loop() --If window has been closed, end the program if self.window:Closed() or self.window:KeyDown(Key.Escape) then return false end local run=0; local rot=0; if self.window:KeyDown(Key.Left) then x=x-0.15; rot=-180; run=1; end if run==1 then self.model[0]:PhysicsSetPosition(x,y,z,0.5) --self.model[0]:SetPosition(x,y,z); self.camera:SetPosition(camx+x,camy+y,camz+z); self.model[0]:SetAnimationFrame(Time:GetCurrent()/40.0,1,"Run") self.model[0]:SetRotation(Vec3(0,rot,0)); end --Update the app timing Time:Update() --Update the world self.world:Update() --Render the world self.world:Render() --Refresh the screen self.context:Sync(true) --Returning true tells the main program to keep looping return true end Quote Link to comment Share on other sites More sharing options...
Skrakle Posted March 2, 2015 Author Share Posted March 2, 2015 Here are some screenshots: Simple model moving on a terrain. When the model encounter bumps/collisions, it is pushed back and falls down. Obviously i'm missing something and i searched every post that i could find about it but no luck. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 2, 2015 Share Posted March 2, 2015 If you use PhysicsSetPosition(), and your models are near each other, one of the models is placed inside the other model. This will result in twitching physics. Instead of using SetPosition(), push the player around with using forces. Quote Link to comment Share on other sites More sharing options...
Skrakle Posted March 2, 2015 Author Share Posted March 2, 2015 Thanks for the reply! I've tried what you suggested, i was able to make it move using AddForce but the movement it's very erratic and when it stops, it sort of slides and falls down and the same problem occurs when it hits a bump in the terrain, the model is pushed away and falls to the ground again and i haven't used PhysicsSetPosition nor SetPosition this time. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 2, 2015 Share Posted March 2, 2015 You can use SetFriction() to prevent sliding. Also SetPosition, SetScale and SetRotation break the physics simulation. If you have an object that you want to move by physics, you can only use the Physics variant of the commands I listed in the previous line. Quote Link to comment Share on other sites More sharing options...
Skrakle Posted March 2, 2015 Author Share Posted March 2, 2015 Thanks but it's not working. Also, i find SetForce very unpractical to move something, my character moves too fast and it seems that a value below 100 won't move it at all. So right now i'm at a loss, i have very little experience with 3D which is why i bought this and i'm surprised that i haven't found a sample project with an example about how that's done. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted March 2, 2015 Share Posted March 2, 2015 It will be hard to manage if you use phycis Add forces, impossible to be precise. With PhysicsSetPosition you must prevent non needed character rotations : self.Entity:SetOmega(0,0,0) The other problem is if encountering an obstacle using PhysicsSetPosition(), physics are jittering against obstacles and character can go throught collision if you use big values for PhysicsSetPosition. So you'll need a raycast (Pick()) function call , to determine if an obstacle is in front of player, in that case just don't call PhysicsSetPosition if the player is pressing forward key. Perhaps i'm stupid, but why don't you use Character Controller ? Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Skrakle Posted March 2, 2015 Author Share Posted March 2, 2015 Perhaps i'm stupid, but why don't you use Character Controller ? If you mean setting the collision types then yes, i've tried entity:SetCollisionType(Collision.Character) as well. Right now i'm not concerned about colliding with other objects/entities because i was planning on using AABB for them, it's moving on the terrain's surface that i'm having a hard time with. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted March 2, 2015 Share Posted March 2, 2015 If you mean setting the collision types then yes, i've tried entity:SetCollisionType(Collision.Character) I mean creating your character in the editor : - choosing character in physics tab - using SetInput in your code Because if you use PhysicsSetPosition then Collision.Character is useless , and you are not using character controller specific behaviour and navmesh navigation. Why don't you use SetINput in your code and make a physic characters controller in the editor ? I can post some TPS code if you need. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Skrakle Posted March 2, 2015 Author Share Posted March 2, 2015 Oh i see, i'll give that a try and i would prefer setting this when the game starts in App:Start() ; is there a way to set it using code? Thanks! Quote Link to comment Share on other sites More sharing options...
Genebris Posted March 2, 2015 Share Posted March 2, 2015 Why don't you just take default player prefab? Quote Link to comment Share on other sites More sharing options...
Skrakle Posted March 2, 2015 Author Share Posted March 2, 2015 I mean creating your character in the editor : - choosing character in physics tab - using SetInput in your code Because if you use PhysicsSetPosition then Collision.Character is useless , and you are not using character controller specific behaviour and navmesh navigation. Why don't you use SetINput in your code and make a physic characters controller in the editor ? I can post some TPS code if you need. That did the trick and I was able to set everything up at runtime since i didn't want to add the characters from the editor. Thanks a lot! Quote 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.