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.

Newcomers AppGameKit Corner / [SOLVED] Fixtoscreen physics question

Author
Message
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 30th Jun 2020 23:46
So I've seen that you should not use fixtoscreen if using physics. When making a side scroll game what are some better ways of handling physics or keeping the sprite screen position while scrolling? I've come across a post talking about screen to world commands but haven't found any good tutorials on the subject.

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

Go to answer

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 1st Jul 2020 02:16
Thanks for responding blink. I'm using fixsprite to screen for the character now. What I'm trying to do is have a obstacle in the way like a vehicle or roadblock to where the player has to walk around it but even with the physics on he travels right through or glitches around. I'm using only the players x position as view offset so the character can only move up and down while staying at about 1/3 of the screen width.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 1st Jul 2020 03:55 Edited at: 1st Jul 2020 03:56
So are your making a side scroller something like this?


Characters can move left/right and up/down
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 1st Jul 2020 04:28 Edited at: 1st Jul 2020 04:29
yes i am.... ive tried moveing the character around without the view off set and fix to screen just to get a grasp on using physics i have the car set to 1 and the player set to 2.... shouldnt the car stop the player from moving in this case? it bounces a little but passes right through. the car is stationary btw as well
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 1st Jul 2020 05:12
Are you using 2D physics or 3D physics?
What command(s) do you use to move the player?
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 1st Jul 2020 05:30
This post has been marked by the post author as the answer.
yes im using 2d physics and im moving the player with a virtual joystick

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 1st Jul 2020 05:42 Edited at: 1st Jul 2020 05:45
If the player is a dynamic object you cannot move it using setspriteposition(), you need to use force or impulse or velocity
if the player is a kinematic object then it will not collide with static objects

https://www.appgamekit.com/documentation/Reference/Sprite/SetSpritePhysicsForce.htm
https://www.appgamekit.com/documentation/Reference/Sprite/SetSpritePhysicsImpulse.htm
https://www.appgamekit.com/documentation/Reference/Sprite/SetSpritePhysicsVelocity.htm

My advice is not to use physics
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 1st Jul 2020 05:45
thanks a lot blink ! i will study these links and see what i can do
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 1st Jul 2020 05:56
Quote: "I've seen that you should not use fixtoscreen if using physics. "

+
Quote: "I'm using fixsprite to screen for the character now."

=

don't use FixSpriteToScreen() for this; SetViewOffset() is where you need to be
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 1st Jul 2020 16:12 Edited at: 1st Jul 2020 17:01
haha yeah i guess those quotes are confusing nomad . what i ment was i was using fixtoscreen before attempting to use physics. Yes im for sure sticking with setviewoffset().Blink
Quote: "My advice is not to use physics"
if i dont use physics whats some other ways to create an obstacle ? im testing something like this currently
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 1st Jul 2020 22:20
Yes. I think GetSpriteCollision() should work for you. You can use SetSpriteShape() to define the sprites collision shape
In your code i note you use SetSpritePosition() to position your sprite which will position the sprite's top left corner so your math should probably be dummyp.x = getspritex(car.id) - GetSpriteWidth(dummyp.id)
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 1st Jul 2020 22:52
That's actually exactly what I'm doing now and it's seems to be working better. Thank you both for the help

Login to post a reply

Server time is: 2024-04-26 12:17:40
Your offset time is: 2024-04-26 12:17:40