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 / AGK 2 Tier 1 SetSpritePhysicsImpulse relates to FPS?

Author
Message
Multicoder
AGK Developer
10
Years of Service
User Offline
Joined: 25th Oct 2014
Location: Germany
Posted: 5th Jan 2016 23:32 Edited at: 5th Jan 2016 23:36
Hey fellow AGKlers

I want to shoot an arrow in the direction the mouse is pointing.
To shoot the arrow I use SetSpritePhysicsImpulse() .

It's working pretty fine - at least as long as the framerate stays the same.
Somehow it seems the force applied to the arrow sprite gets stronger the higher the fps are.
The force applied to the character sprite using SetSpritePhysicsForce() and - and that's kind of strange - the force when jumping the character using SetSpritePhysicsImpulse() are not affected by this.
Due to the fact, that the character behaves as it should, I think, the problem is within my code.

Here is a short video showing the problem in action (inline video seems not to work): https://youtu.be/czydbMHhiZs

This is the main code I use to shoot the arrow:


Do you have any idea what is causing that behavior and how I can fix it?
I already tried manipulating StepPhysics() based on the current fps but to no avail. And since the forces on the character are fine, I don't think that is the problem.

Codin' regards
Daniel
Yes, I am aware that I sound like a caveman to native english speakers
mrradd
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: CA, USA
Posted: 5th Jan 2016 23:43

Are you updating the Force at any point? Force affects the movement of the object and needs to be constantly applied every cycle.
make -C ../NagGaCreMo/2016 -f aGame.mk
Multicoder
AGK Developer
10
Years of Service
User Offline
Joined: 25th Oct 2014
Location: Germany
Posted: 6th Jan 2016 00:11
Since it's only an impulse, it only needs to be applied once
But no, I don't. I already checked that.
Yes, I am aware that I sound like a caveman to native english speakers
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 6th Jan 2016 00:14
Apologies I haven't had the chance to read your entire post, but have a look at this thread from a while ago... It may be relevant...

https://forum.thegamecreators.com/thread/204311
Using AppGameKit V2 Tier 1
Multicoder
AGK Developer
10
Years of Service
User Offline
Joined: 25th Oct 2014
Location: Germany
Posted: 6th Jan 2016 00:56 Edited at: 6th Jan 2016 01:40
Thanks for linking that thread!

The snippet in that thread kind of fixes the general direction of the arrow but is causing a whole bunch of other problems:
- the arrows "spray" randomly when shoot-button is spammed
- the arrows still fly faster the higher the framerate is (but the flying curve is almost the same regardless of the fps)
- walking doesn't work anymore with high fps (but works with lower fps like 120)
- jumping with high fps stutters (but works with lower fps like 120)

I played a bit with the physicsstep# variable, but as soon as - for example: walking - works with high fps, the character is almost lightning fast with low fps.


It is strange, that SetSpritePhysicsImpulse() works well at all framerates when jumping, but bugs out when shooting an arrow. I think, there must be a very special bug - either in my code or in agk.
Yes, I am aware that I sound like a caveman to native english speakers
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 6th Jan 2016 09:47
From the docs for SetSpritePhysicsImpulse:
Quote: " changes the velocity with the equivalent power of a similar force applied for 1 second."
Maybe the calculation is based on applying a force every frame for one second (hence a different force being applied depending on frame rate)... doesn't explain why the jump impulse works though It should be possible to compensate with a divisor on the gap between x1#/x2# and y1#/y2# based on current framerate. Maybe an alternative solution would be to use a mousejoint?



V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Multicoder
AGK Developer
10
Years of Service
User Offline
Joined: 25th Oct 2014
Location: Germany
Posted: 6th Jan 2016 10:41
I found out that everything works as it should at all framerates when I reduce the impulse vector.
But the arrow doesn't fly as far as it should when I do this.
So I tried reducing also the mass of the arrow and - again - there are the same framerate related issues. -.-
Yes, I am aware that I sound like a caveman to native english speakers
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 6th Jan 2016 11:41
Sounds like you're hitting some internal box2d limits. Changing the physics scale will probably fix it. See http://www.appgamekit.com/documentation/Reference/2DPhysics/SetPhysicsScale.htm
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Multicoder
AGK Developer
10
Years of Service
User Offline
Joined: 25th Oct 2014
Location: Germany
Posted: 6th Jan 2016 12:32
That's it!
Thank you so much! I wouldn't have thought of this in thousand years!
I changed the scale to 0.05 and changed the vector again and now everything works as expected. I have to change all forces according to the new scale, but I guess that's the price for shooting arrows
Yes, I am aware that I sound like a caveman to native english speakers
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 6th Jan 2016 15:00
Glad I could help
V2 T1 (Mostly)
Phone Tap!
Uzmadesign

Login to post a reply

Server time is: 2024-11-25 13:40:58
Your offset time is: 2024-11-25 13:40:58