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 / SetSpritePhysicsForce and rotating sprite

Author
Message
mrradd
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: CA, USA
Posted: 10th Sep 2015 20:45
I am making a physics based Tetris game just for fun, but I am having issues when applying force and the sprite is rotating from force applied.

When a block drops, the player can control its left and right movement as well as rotation. The sprite's position is changed using SetSpritePhysicsForce. The sprite is set to be able rotate--I want to maintain this. When force is applied, the sprite rotates which is not the desired effect--rotation will be handled some other way. I read in the docs that the sprite will rotate about its COM if the force vectors applied are not inline with COM. No matter what I have tried I cannot get the COM's Normal (correct term in this case?) to apply a force that will not cause rotation.

I'd include a code snippet, but I deleted the lines out of frustration haha. I couldn't find anything on here about this kind of issue, so some assistance would be appreciated. I tried some Sin/Cos stuff to find angles to no avail. My calculus and trig knowledge has fallen out of my brain since college, but I can understand it if you guys have to talk like that.

Any help is greatly appreciated. I am using Tier2 but Tier1 stuff is the same, so either is fine. Have some fake beers as a thank you for reading

-mrradd-
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 11th Sep 2015 10:42
Try using SetSpritePhysicsVelocity instead of applying a force maybe

My hovercraft is full of eels
mrradd
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: CA, USA
Posted: 11th Sep 2015 11:10
@lilpissywilly I like that idea and tried it. My issue now is how do I maintain the increase in the Y component of the velocity while changing the X component? The sprite continues to fall, but it is not in a way that feels natural. I tried getting the current velocity in the Y Direction and using that to set the new velocity thinking it would continue to update, but of course it didn't. I would need to calculate the next value of the Y component to continue a natural feel. Am I over thinking this?

-mrradd-
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 11th Sep 2015 13:05 Edited at: 11th Sep 2015 13:07
SetSpritePhysicsVelocity(sprite, yourXvalue, getSpritePhysicsVelocityY(sprite)) ?

Psuedo-code that is, the getSpritePhysicsVelocityY might have a different syntax


Edit: I read your whole post after answering And maybe that is what you tried. If that is what you have tried already lemme think about it for sec

My hovercraft is full of eels
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 11th Sep 2015 13:09
Other than that, you could store the sprites angle and set it manually to that angle while the X is being manipulated by the user. Or if that doesn't work because you want to be able to slide the sprite next to others maybe set the Angular Damping higher so it doesn't rotate so easily by a force?

My hovercraft is full of eels
mrradd
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: CA, USA
Posted: 11th Sep 2015 18:57
Quote: "
SetSpritePhysicsVelocity(sprite, yourXvalue, getSpritePhysicsVelocityY(sprite)) ?

Psuedo-code that is, the getSpritePhysicsVelocityY might have a different syntax

Edit: I read your whole post after answering And maybe that is what you tried. If that is what you have tried already lemme think about it for sec
"


That is exactly what I did.

Quote: "Other than that, you could store the sprites angle and set it manually to that angle while the X is being manipulated by the user. Or if that doesn't work because you want to be able to slide the sprite next to others maybe set the Angular Damping higher so it doesn't rotate so easily by a force?
"


I'll try this one out. I didn't consider persisting the angle in this manner. I haven't toyed with angular damping yet, but I will look into both methods. Maybe I'll end up with a combination of the two--I don't know. I'll post what I come up with.

-mrradd-
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 11th Sep 2015 20:29
Yeh good luck and keep posting, I've used box2d a bunch with AppGameKit and most of the time I can find a workaround for the issues I come across in how I want to implement it

My hovercraft is full of eels
Doz
16
Years of Service
User Offline
Joined: 16th Apr 2008
Location:
Posted: 12th Sep 2015 07:54
If you're going for a faster falling effect, maybe crank up the gravity value instead of a force on the pieces.

"The trouble with quotes on the Internet is that you can never know if they are genuine." -Abraham Lincoln
mrradd
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: CA, USA
Posted: 13th Sep 2015 00:36 Edited at: 13th Sep 2015 00:41
Quote: "If you're going for a faster falling effect, maybe crank up the gravity value instead of a force on the pieces."

What I was trying to do, was allow it to move Left/Right while maintaining the pull in the Y direction from gravity.

I solved my problem! Turns out I had a stupid logic error....... It's one of those things that wasn't easy to find, but when you do you're like "WTF was I thinking?" I found it by reviewing my code from previous projects. That's when I found the below code from my first program. I tested it, and noticed the behavior was different even though the code was mostly the same. An excerpt from my code is below. I'd provide an example of the actual problem, but it is really embarrassing.



Thanks, for the help! In all actuality you guys helped me a ton simply by allowing me to brainstorm off of your suggestions which lead me to remember about the first program I made with AGK2.

-mrradd-

Login to post a reply

Server time is: 2024-09-29 05:24:48
Your offset time is: 2024-09-29 05:24:48