Adam's Lair Forum

game development and casual madness
It is currently 2019/12/12, 07:49

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: 2015/01/14, 21:44 
Forum Adept
Forum Adept

Joined: 2014/12/13, 00:11
Posts: 398
Location: Brazil
Role: Gamer
I was watching Adam's video Duality: Physical Platformer, and I tried to do the most physically correct approach for a platformer game.

However, I didn't understand what he was doing because the video was accelerated, and, trying to replicate what he did, my character does not work the exact same way as his.

Can any of you explain me how to do it, please?

_________________
I only know the basics of C#. I have no advanced knowledge.


Top
 Profile  
 
PostPosted: 2015/01/14, 22:58 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2073
Location: Germany
Role: Professional
RockyTV wrote:
Can any of you explain me how to do it, please?


Honestly, I think it isn't worth it to elaborate in detail. I was experimenting with the concept myself back then and wouldn't recommend anyone to do it the way I did - which was basically, creating a compound object of two GameObjects with RigidBodies, which were joined together using a physics Joint that the player would unknowingly apply a rotational force to. The players avatar would move on wheels - including all of the usual problems that wheels might have, like losing friction or getting stuck. :rolleyes:

I've also come to the conclusion that platformers simply are not built to be physically correct. Sure, there's Limbo and the like, which do make a good use of physics - but it goes only so far. When doing a platformer, making character controls feel good should be your first and foremost priority.

So, here's my advice: Just create a simple GameObject with a RigidBody, set its mass to a fixed value and then move it by applying forces, impulses and velocities directly. Do whatever it takes. Screw physics, unless it's useful. ;)

Unfortunately, I can't tell you exactly how to create good character controls, because my experiment ended with the video you're mentioning :| Instead, here are some hopefully useful links:


Don't be confused about all this "Box2D" talk - Duality uses a custom fork of the Farseer physics engine, which is basically an improved C# implementation of Box2D. They are definitely not to be considered equal, but very similar - you can use a lot of Box2D advice for Farseer / Duality physics as well!

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2015/01/14, 23:05 
Forum Adept
Forum Adept

Joined: 2014/12/13, 00:11
Posts: 398
Location: Brazil
Role: Gamer
Adam wrote:
RockyTV wrote:
Can any of you explain me how to do it, please?


Honestly, I think it isn't worth it to elaborate in detail. I was experimenting with the concept myself back then and wouldn't recommend anyone to do it the way I did - which was basically, creating a compound object of two GameObjects with RigidBodies, which were joined together using a physics Joint that the player would unknowingly apply a rotational force to. The players avatar would move on wheels - including all of the usual problems that wheels might have, like losing friction or getting stuck. :rolleyes:

I've also come to the conclusion that platformers simply are not built to be physically correct. Sure, there's Limbo and the like, which do make a good use of physics - but it goes only so far. When doing a platformer, making character controls feel good should be your first and foremost priority.

So, here's my advice: Just create a simple GameObject with a RigidBody, set its mass to a fixed value and then move it by applying forces, impulses and velocities directly. Do whatever it takes. Screw physics, unless it's useful. ;)

Unfortunately, I can't tell you exactly how to create good character controls, because my experiment ended with the video you're mentioning :| Instead, here are some hopefully useful links:


Don't be confused about all this "Box2D" talk - Duality uses a custom fork of the Farseer physics engine, which is basically an improved C# implementation of Box2D. They are definitely not to be considered equal, but very similar - you can use a lot of Box2D advice for Farseer / Duality physics as well!


Thanks! Will take a look later. At the moment I'm using Transform.MoveBy, since I don't want the character to keep walking when it should be standing still. However, I've come across a problem: if you keep jumping, and walk, at the same time, you'll eventually "fly". I don't know how to fix that, tho.

_________________
I only know the basics of C#. I have no advanced knowledge.


Top
 Profile  
 
PostPosted: 2015/01/14, 23:24 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2073
Location: Germany
Role: Professional
Quote:
At the moment I'm using Transform.MoveBy


When you're using a RigidBody, a better way would be to just set the RigidBodies LinearVelocity property to the value you want. Otherwise, your RigidBody will "sink into" barriers when you push hard enough - because Transform just override physical behavior and collision detection.

As for the flying problem, you should only let the player jump when their avatar has contact with the ground. To check that, you could do a physics raycast using RigidBody.Raycast, to see if the characters feet are on the ground.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2015/01/14, 23:37 
Forum Adept
Forum Adept

Joined: 2014/12/13, 00:11
Posts: 398
Location: Brazil
Role: Gamer
Adam wrote:
Quote:
At the moment I'm using Transform.MoveBy


When you're using a RigidBody, a better way would be to just set the RigidBodies LinearVelocity property to the value you want. Otherwise, your RigidBody will "sink into" barriers when you push hard enough - because Transform just override physical behavior and collision detection.

As for the flying problem, you should only let the player jump when their avatar has contact with the ground. To check that, you could do a physics raycast using RigidBody.Raycast, to see if the characters feet are on the ground.


I thought it would be similar to Unity's Physics.Raycast, but it is not quite the same. Can you give me an example?

_________________
I only know the basics of C#. I have no advanced knowledge.


Top
 Profile  
 
PostPosted: 2015/01/14, 23:51 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2073
Location: Germany
Role: Professional
The DualStickSpaceShooter project uses a lot of Raycasts for AI and certain gameplay checks. Here's a line-of-sight check as an example on how to use the Raycast method: Link

You're basically passing a delegate that handles each Raycast hit and provides information on what to do with the ray in further calculation. It is documented here what effect each return value has. Optionally, the Raycast method cal conclude by returning the first hit object - which you can use for your gameplay logic.

It will take a little bit of experimenting on your side to do this - as your requirements are quite specific, there is no general solution to this, but you'll have to engineer one that fits your needs.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2015/01/15, 00:22 
Forum Adept
Forum Adept

Joined: 2014/12/13, 00:11
Posts: 398
Location: Brazil
Role: Gamer
Adam wrote:
The DualStickSpaceShooter project uses a lot of Raycasts for AI and certain gameplay checks. Here's a line-of-sight check as an example on how to use the Raycast method: Link

You're basically passing a delegate that handles each Raycast hit and provides information on what to do with the ray in further calculation. It is documented here what effect each return value has. Optionally, the Raycast method cal conclude by returning the first hit object - which you can use for your gameplay logic.

It will take a little bit of experimenting on your side to do this - as your requirements are quite specific, there is no general solution to this, but you'll have to engineer one that fits your needs.


Experimented it, didn't work as expected :(, still has the same bug. I'll see if I can fix it.

EDIT: actually, it wont detect that I'm on the ground object...
EDIT²: found out the issue (hopefully!). My character is standing on the ground, and its transform.Y value is -77, while the ground's transform.Y value is 28. Will have to do use some advanced skills here to fix this.

_________________
I only know the basics of C#. I have no advanced knowledge.


Top
 Profile  
 
PostPosted: 2015/01/15, 09:34 
Veteran Member
Veteran Member
User avatar

Joined: 2015/01/07, 09:58
Posts: 102
Location: Sweden
Role: Hobbyist
What I have found to work the best was just using a box for the body and a circle for the feet of the character. Just like adams tutorial. But lock the rotation on the fixtures of the body and apply some damping instead. Just move it by applying forces. As simple as that.

I had some scenarios where a wanted more control of the movement, which can be done by manually setting the linear velocity.

It looked like this:
https://pbs.twimg.com/tweet_video/B1nBN_uIcAAlPl4.mp4


Top
 Profile  
 
PostPosted: 2015/01/15, 14:25 
Forum Adept
Forum Adept

Joined: 2014/12/13, 00:11
Posts: 398
Location: Brazil
Role: Gamer
skoggy wrote:
What I have found to work the best was just using a box for the body and a circle for the feet of the character. Just like adams tutorial. But lock the rotation on the fixtures of the body and apply some damping instead. Just move it by applying forces. As simple as that.

I had some scenarios where a wanted more control of the movement, which can be done by manually setting the linear velocity.

It looked like this:
https://pbs.twimg.com/tweet_video/B1nBN_uIcAAlPl4.mp4


I don't know how to set it up, so I'll just go with the linear velocity approach. Thanks anyways.

_________________
I only know the basics of C#. I have no advanced knowledge.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group