Adam's Lair Forum

game development and casual madness
It is currently 2017/10/18, 02:13

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: 2016/09/23, 01:28 
Novice Member
Novice Member
User avatar

Joined: 2016/09/19, 12:38
Posts: 24
Role: Observer
Code:
float rayCastLength = 33.0f;
            RayCastData firstHit;

            bool hit_ground = RigidBody.RayCast(this.transform.Pos.Xy, this.transform.Pos.Xy + new Vector2(0, rayCastLength), data =>
            {
                if (data.Shape.IsSensor) return -1;
                return data.Fraction;

            }, out firstHit);

            VisualLog.Default.DrawConnection(this.transform.Pos.X, this.transform.Pos.Y, this.transform.Pos.Z, this.transform.Pos.X, this.transform.Pos.Y + rayCastLength);

           
            Log.Game.Write(hit_ground.ToString());


After trying to understand, i came with this code. My sprite has 64 pixels in height, so the rayCastLength set to 33.0f means 1 pixel below the sprite. The log give me that this is right, but i could not understand (even reading a lot) what is the data.Fraction...why returning it works in this case. But still, thinking in the future, adding gravity and everything else, I see that this isn't the best solution.

In Game Maker, I used to make this approach:
Code:
if (place_meeting(x, y + velocity.y, obj_solid) // check if the position on the first two parameters are colliding with the object in the third parameter.
{
     while(!place_meeting(x, y + sign(velocity.y), obj_solid)) // move 1 pixel while not colliding
     {
          y += sign (velocity.y);
     }
     velocity.y = 0;
}


So, basically, is check if the next frame the player will collide with the ground. If yes, stop moving, if no, you can move and then actually move. In other game engines, its seen so easy to make. But here, like in the unity engine, its seen hard to achieve. But as I said before, I found the Engine I was looking for :] xD and want to learn it, and maybe some day contribute with tutorials about it!

EDIT: I am reading about Rigidbody.PickShapeGlobal(Vector 2) and Rect class. Could them be used for collision?


Top
 Profile  
 
PostPosted: 2016/09/23, 16:59 
Novice Member
Novice Member
User avatar

Joined: 2016/09/19, 12:38
Posts: 24
Role: Observer
I have done! Finally! Well, i don't know if is the best way of doing it, but now is working fine. All I do was, instead of using 32x32 tiles and each of them having its own collision shape, I create a gameobject parent, and its childrens was the 32x32 blocks. Then I add the rigidbody and collision shape to the gameobject parent, so it has only one collision shape. Set the values of restitution, friction to 0.

Now the player is dynamic rigidbody type, and I don't have to worry about the collisions. If you guys wish, I can make a video explaining how I made (some sort of tutorial).

Thanx everybody!


Top
 Profile  
 
PostPosted: 2016/09/23, 22:54 
Veteran Member
Veteran Member
User avatar

Joined: 2015/10/04, 15:48
Posts: 162
Location: Germany
Role: Hobbyist
Good to hear that it works :1+:

gtkampos wrote:
Now the player is dynamic rigidbody type, and I don't have to worry about the collisions. If you guys wish, I can make a video explaining how I made (some sort of tutorial).


Jeah, why not. I would be glad ^^

_________________
Twitter | GitHub | Join Duality on Discord | itch.io


Top
 Profile  
 
PostPosted: 2016/09/29, 21:09 
Junior Member
Junior Member

Joined: 2016/05/15, 18:27
Posts: 45
Role: Hobbyist
loeller wrote:
Hello gtkampos, and welcome to the forums!

In my opinion, you should avoid rigidbody based 2D controllers. It seems the easier solution at first, because you don't have to implement collision checking and all that by yourself, but in the long run, it doesn't worth it. You will struggle with fine tuning the controller's dynamics, and a platformer game with crappy movement is not the thing players tolerate. So stick with a custom physics-free controller unless you have a good reason to use physics.

So, there stays the question, how to implement the controller. On Youtube, there is an excellent series about that, it's fast-paced, high-level and well-explained, using Unity. You mentioned it's familiar, and it's no big deal porting it to Duality. I've already started that, but only the codebase of the first 3 episodes. It cannot handle slopes, nor moving platforms, but ideal for a game using the tilemap plugin for example (I used it in my Tilemap Jam entry). If you extend it, it'd be great if you shared your progress. ^^ If you have questions regards my code, or anything else, feel free to ask!


Hey man. I'd like to use the raycast controller, but have one issue. How can I manually add forces to the player? I wish to add knockback whenever the player is damaged, but cannot directly AddForce() as it is not a rigidbody.

Can you help me develop a method that could handle this?
Thanks :D


Top
 Profile  
 
PostPosted: 2016/09/30, 01:47 
Junior Member
Junior Member

Joined: 2016/05/15, 18:27
Posts: 45
Role: Hobbyist
loeller wrote:
Hello gtkampos, and welcome to the forums!

In my opinion, you should avoid rigidbody based 2D controllers. It seems the easier solution at first, because you don't have to implement collision checking and all that by yourself, but in the long run, it doesn't worth it. You will struggle with fine tuning the controller's dynamics, and a platformer game with crappy movement is not the thing players tolerate. So stick with a custom physics-free controller unless you have a good reason to use physics.

So, there stays the question, how to implement the controller. On Youtube, there is an excellent series about that, it's fast-paced, high-level and well-explained, using Unity. You mentioned it's familiar, and it's no big deal porting it to Duality. I've already started that, but only the codebase of the first 3 episodes. It cannot handle slopes, nor moving platforms, but ideal for a game using the tilemap plugin for example (I used it in my Tilemap Jam entry). If you extend it, it'd be great if you shared your progress. ^^ If you have questions regards my code, or anything else, feel free to ask!



I think your code may have a bug? I'm getting a "Cannot access a disposed object" error. And I copied + pasted it straight from your link.

Code:
[Edit] Error:   An error occurred: ObjectDisposedException: Cannot access a disposed object.
Object name: 'LogEntryList'.
CallStack:
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.Control.get_Handle()
   at System.Windows.Forms.Control.PointToClientInternal(Point p)
   at Duality.Editor.Plugins.LogView.LogEntryList.OnContentChanged() in c:\projects\duality\DualityEditorPlugins\LogView\Modules\LogEntryList.cs:line 417
   at Duality.Editor.Plugins.LogView.LogEntryList.AddEntries(LogEntry[] entries, Int32 count) in c:\projects\duality\DualityEditorPlugins\LogView\Modules\LogEntryList.cs:line 271
   at Duality.Editor.Plugins.LogView.LogEntryList.ProcessIncomingEntries(LogEntry[] entries, Int32 count) in c:\projects\duality\DualityEditorPlugins\LogView\Modules\LogEntryList.cs:line 360
   at Duality.Editor.Plugins.LogView.LogEntryList.timerLogSchedule_Tick(Object sender, EventArgs e) in c:\projects\duality\DualityEditorPlugins\LogView\Modules\LogEntryList.cs:line 683
   at System.Windows.Forms.Timer.OnTick(EventArgs e)
   at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)



EDIT:
So I restarted, and it didn't throw up any errors. It did, however, not function as it was (seemingly) intended to.
It seems I have absolutely no idea what I'm doing.

Image



Can you provide instructions as to how these scripts are to be used?


EDIT 2:
So I'm an idiot. First of all, have a platform with a rigidbody on it so the player can land on it. Second, attach the 2 scripts to your selected player object. Next, fill in the values (DO NOT LEAVE THEM ALL 0, OTHERWISE THE PLAYER'S POSITION WILL BE FORCED TO 0 EVERY FRAME).



I forgot to fill in the values :(


Top
 Profile  
 
PostPosted: 2016/09/30, 18:12 
Veteran Member
Veteran Member
User avatar

Joined: 2016/01/10, 10:56
Posts: 148
Location: Budapest
Role: Hobbyist
yeah, this code is not really "production ready". The properties should be preinitialized to reasonable values.
Anyway, if I'm getting it right, you finally made it work ^^


Top
 Profile  
 
PostPosted: 2016/09/30, 22:10 
Novice Member
Novice Member
User avatar

Joined: 2016/09/19, 12:38
Posts: 24
Role: Observer
Check this thread about the tutorial i am talking about.

http://forum.adamslair.net/viewtopic.php?f=18&t=954


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 8 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