Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] Help with Sticking to a kinematic Sprite

Author
Message
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 28th Sep 2021 07:07
Ok so moving onto the platform for my platform game.

There is no platform game if I fall of the platform lol.

I tried this but well, its poorly written, just trying to do something

The author of this post has marked a post as an answer.

Go to answer

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 28th Sep 2021 11:03
Box2D takes care of this for you, your player should be knimatic, your platform should be static, box2D does the the rest, you only need to check for collisions if you want a reaction from that collision.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 28th Sep 2021 21:36

Box2D?

Where to buy this at?

Thank you
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Sep 2021 21:46 Edited at: 28th Sep 2021 21:48
a version of Box2D is implemented in AGK. it's the 2D and Sprite Physics system.
[My Itch.io Home] [AGK on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 28th Sep 2021 22:03
Virtual Nomad

So what is the box 2d code for what I am needing?

All i want to do is make my player sprite stay on a platform.

I am setting up trigger boxes but this should not have to be done, Im guessing.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Sep 2021 23:12 Edited at: 28th Sep 2021 23:21
all of THIS is giving me deja vu, and everyone has a different approach but basic platformer mechanic using built-in physics:


PS the red box is push-able
[My Itch.io Home] [AGK on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 28th Sep 2021 23:29

Virtual Nomad

There is no moving platforms in this example that I'm standing on?
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Sep 2021 23:54
where did you say the platforms were moving?

regardless, if you're on a moving platform, add the platform's X/Y velocity to the player's velocity.
[My Itch.io Home] [AGK on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 29th Sep 2021 00:03
Virtual Nomad

I did, but it does not work, its in my code in the first post.

All it does is move my player sprite to the end of the level.

I believe its because of physics.

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 29th Sep 2021 00:14
sorry but that code doesn't contain platform movement and "Sticking to a kinematic Sprite" could mean a few things.

again, since it seems you're moving forward with using physics, add the platform's X/Y velocity to the player's velocity.

even if you don't use physics, add the platform's x/y change to the player's x/y when the player is standing on a platform (it really doesn't matter if it's moving where the "x/y change" will only add 0,0 if it isn't).
[My Itch.io Home] [AGK on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 29th Sep 2021 00:22
Here is the function

all I know is when I add

SetSpritePosition(player,Playerx+plx,Playery)

my sprite ends at the end om my whole level

but when I just put

SetSpritePosition(player,plx,Playery)

I'm stuck to the platform and cant move

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 29th Sep 2021 00:55
A moving platform should also be kinematic and will move another kinematic sprite by its self DO NOT use SetSpritePosition while using physics let the physics engine do its work, when you call SetSpritePosition you confuse the physics simulation

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 29th Sep 2021 01:02 Edited at: 29th Sep 2021 01:03
Quote: " when you call SetSpritePosition you confuse the physics simulation"


Yes so I'm confused what to do

There is no examples
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 29th Sep 2021 01:30
I don't get what you are not getting??

make a player, set it kinematic, create a platform, make it static if it does not move, kinematic if it does move.

have your player jump onto the platform, the physics engine (Box2D) does the rest ....

I cant explain it any simpler than that!

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 29th Sep 2021 01:43 Edited at: 29th Sep 2021 01:46
When I set my player to kinematic he gets no physics or movement from SetSpritePhysicsImpulse

Kinematic is a special case which can be thought of as a moving static body, it will not respond to collisions or forces and will continue at its specified velocity forever, but dynamic items will respond to it and effectively be pushed out of the way.

this is hw I'm moving my player sprite

SetSpritePhysicsImpulse( player, GetSpriteXByOffset(player), GetSpriteYByOffset(player), GetVirtualButtonState(2)/max_speed#, 0.0 )
SetSpritePhysicsImpulse( player, GetSpriteXByOffset(player), GetSpriteYByOffset(player), GetVirtualButtonState(3)/-max_speed#, 0.0 )
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 29th Sep 2021 02:05 Edited at: 29th Sep 2021 02:18
1st: i'm using Dynamic sprites, not Kinematic, for moveable stuff. see HERE.

2nd: you haven't been very clear in many of your questions which requires others to guess at what you want. when your title includes Kinematic, some will assume "moving" vs "static" not strict kinematic because i'm not sure why you'd use true kinematic unless you're trying to mix standard sprite stuff with physics sprite stuff (which you have been and it's not recommended to mix multiple methods of moving sprites - for example, using SetSpritePosition on a Physics sprite breaks its physics for that loop cycle)),

3rd: you've revealed that you're using a move method that i'm not using in the example above (impulses); see # 2. it all matters.

4th: i won't re-write this. the notions are in there (crudely implemented) so you can adapt it however you want:

[My Itch.io Home] [AGK on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]

Attachments

Login to view attachments
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 29th Sep 2021 02:07 Edited at: 29th Sep 2021 02:08
I think impulse and force only affect dynamic objects, for kinematic use velocity or maybe try setting the player as dynamic but you will need to add dampening and rotation settings to the sprite or it will just float around uncontrolled (Look for: dampening, angular damping and can rotate), usually things like players, enemy's and moving platforms are kinematic

A kinematic body should collide with a static body and another kinematic body that ^^ just means it will not move like a dynamic body does, a static body should stop a kinematics movement ...

I will play with some code tomorrow to conform this, now even I am confused!!!


Edit:: what ^^ he said!
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 29th Sep 2021 02:11
Virtual Nomad

Looks like im going to have to change some code in my game

You are a big help, in moving my player I am not doing this

If Grounded
ThisGround = GetRayCastSpriteID()
PMoveX# = GetSpritePhysicsVelocityX(ThisGround)

Your a big help

Thank you
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 29th Sep 2021 02:34 Edited at: 29th Sep 2021 02:39
you're welcome.

and, i hope you're actually learning from the code and not just pasting. ie, why do you think i added a joint to the movable platform?

we didn't used to be so quick to offer code examples because some new folks just expected others to write their games for them without increasing their own knowledge and someday returning the favor to the "next generation".

the best "thank yous" around here are truly taking what's offered and learning from it. some of us evaluate those we help. if we don't see "learning" and those "thank yous", we stop serving them code.

any code i post IS a big THANK YOU to the MANY that took time to "show me the way", and STILL DO (because i've a long way to go ).
[My Itch.io Home] [AGK on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 29th Sep 2021 03:29


Virtual Nomad

No, I am reading all of your example and learning a lot.

You did a lot of things way different then me and all on all I learned a lot just from a couple lines of code.



is a lot simpler then what I am doing

I will use this for a lot of things like jumping on enemy's to how fast I can fall from gravity



Putting your platform on dynamic I didn't expect and then adding the joint, what is the joint for?


Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 29th Sep 2021 03:42 Edited at: 29th Sep 2021 03:45
This post has been marked by the post author as the answer.
Quote: "what is the joint for?"

remove it and see... this is what i'm talking about. play with it, read up on it, learn.

and, there are other ways to skin that cat. it was the one that came to mind.
[My Itch.io Home] [AGK on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 29th Sep 2021 17:35


Well I completely set up everything perfectly thank God.

It works well and plays better to.

I incorporated a lot of your code into mine.

I changed a couple things but all in all I have better movement and have moving platforms.



Login to post a reply

Server time is: 2024-04-24 05:04:20
Your offset time is: 2024-04-24 05:04:20