Jump to content

Character bouncing with terrain or other entities


Skrakle
 Share

Recommended Posts

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

Link to comment
Share on other sites

Here are some screenshots:

 

Simple model moving on a terrain.

screenshot1.jpg

 

 

 

 

When the model encounter bumps/collisions, it is pushed back and falls down.

screenshot2.jpg

 

 

Obviously i'm missing something and i searched every post that i could find about it but no luck.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 huh.png ?

Stop toying and make games

Link to comment
Share on other sites

Perhaps i'm stupid, but why don't you use Character Controller huh.png ?

 

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.

Link to comment
Share on other sites

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.

Stop toying and make games

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...