box2d: How do I rotate an object on specified amount of degrees smoothly - actionscript-3

I wonder if box2d has some options for doing that?
I am trying to apply angular velocity atm, but don't know where to stop rotating :(...
So object which needed to rotate to 90 degrees, can't stop rotating....

Well I did it adding small angular velocity and comparing to current angle of the object... Not sure why I've asked the question. Everything worked well!

Related

is there a way to rotate an actor's pitch past 90 degrees in unreal engine 4

I a working on a game and for some reason I can't get my component to rotate past 90 degrees pitch. I've distilled it down to EventTick->AddRelativeRotation(0, 5, 0) but when it hits the 90 degrees pitch mark it simply jitters back and fourth. I've read many pages on this topic and I simply cannot find an answer. If anyone can help it would be greatly appreciated.
This is known bug since 2014 but is not fixed yet. One way to get around this is make a rotator before then assign this rotator to target object.
Break old rotation into 3 float values
Make a new rotator adding the offset value from the old rotation (y=5 in your case)
Assign rotation to desired object
Rotations using only three axes can be problematic. Rotations are more stable and reliable when using quaternions. The jittering you mention sounds a lot like something that would be fixed by using quaternion rotation instead.
It can be a bit confusing but there's plenty of documentation about this on the internet now that you have a term to search for.
Then, have a look at this UE forum post: Rotate a mesh around its center using quaternion It contains a link to a video showing how to do rotations using quaternions in UE, and some Blueprint that might help as well.

AS3 - Detect WHERE a collision occurred and ROTATE everything AFTER the collision point of the object by 90 degrees

AS3 - Detect WHERE a collision occurred and ROTATE everything AFTER the collision point of the object by 90 degrees
DISCLAIMER
The following explanation probably makes no sense, so have a look at http://raphaelhennessy.com/misc/Explanation.png for more information
Essentially, I'm making a game where a lazer shines onto the screen and you have a mirror somewhere on the screen you can drag around. There is also a globe somewhere on the screen. The aim of the game is to direct the light, using the mirror, into the globe. Then, an animation plays of the globe filling with light and you progress to the next level.
After time, the levels get somewhat harder and new obstacles and challenges are introduced.
My problem is this; I got the lazer, mirror & globe all on the stage working fine except that I can't figure out how to programmatically make the lazer 'bounce' off the mirror.
Thanks in advance,
-Raph
I figured out how to do this. If you are interested you can find the code at raphaelhennessy.com/misc/LightStage.zip

Customize or create Starling animations, movements and Transitions

Since I don't know english very well, I'm not able to find clear examples and/or tutorials for what I'm trying to do.
So the (maybe stupid) question is:
How can I strongly customize tweens using Starling framework and make my Sprites(or MovieClips) following a line, curve or create every other non-linear movement that doesn't exist in Transition Class?
I have no problem with Basic Starling animation. So it should be a good start point.
Thanks in advance for examples, resources or suggestions.
PS. I already visit the "Starling Wiki" page about custom Transitions but, as a Beginner(almost Intermediate) coder I wasn't able to completely understand it.
I know there are many online resources about AS3/Starling/Flash/Nape/Box2D but it's not easy for a non-english Beginner programmer to understand them.
You can simple move Starling's movieClip by set .x .y .rotation
Since now, I haven't heard of scripted transition to make predefined non linear movement. As you said, you can move object from one position to another, but it won't happen in a curved line.
What I've done in the past is to predefine the path of the movement, as I needed exactly the same weird path. I did a path tween in Flash, then used one simple function to loop through all frames (using gotoAndStop()) and getting x and y property of the object, storing them in an array. This was done when initializing. Later on I could start animation on all my weird paths whenever I wanted, using onUpdate method of tween, and passing positions from the array I've populated in the beginning.
This of course is good if you have very weird paths. If you want very little curves, you could try to do a mathematical equation. Tween classes have an update function, which will be called on each frame. So on each frame you could do some calculations and modify the parameters. For example if you tween x and y properties, you could use the update function to add a random number to those values. Of course this will make very uncontrolled movement, I'm just giving an example.
The best solution I could think of, speaking of complexity/result ratio - to use Greensock's TweenMax (look at the second example) - it has a built in bezier tweening. This means it could move from point A to point B within a bezier curve. I think this will be a good solution for your problem :)

Flash AS3 - Centering camera on player when scaling in and out (zooming)

I am building a survival horror like game and am hoping to make a very nice camera system to compliment the mechanics. Part of this is the fact that you will be able to crouch down and cover your face. The camera work I want to do with this is to zoom in to the character in order to constrain the view for the player as well.
The current MC structure that I have is:
GameMaster
>
Spawner (this is for the player and all enemies)
>
Player
The issue I'm having is that scaling the GameMaster (which is where side scrolling and other global game effects are happening) causes the centering of the camera to offset based on how far away the player is from 0,0.
You can see the issue clearly in this video. The red arrows point to the 0,0.
On this stackoverflow question the answer says to make a container for everything and center the containers 0,0 over the target that you want to zoom around. This poses a challenge for me because I would then have to get proper coordinates for an object nested 4 MC's in. I'm also unsure what that will then do for my current side scrolling camera.
Is there a way that I could mathematically figure out the offset when the character ducks? It seems like a viable option because you can't move until you let go of crouch and the camera zooms out.
If not, is the container MC a good option or is it just one of those "you gotta do what you gotta do." type situations?
[Added]
I also see something about Transform Matrices or something. Is that something that would work? I know NOTHING about them but I assume they are CPU heavy and wouldn't be a good option for a mechanic prevalent throughout the whole game.
[Added 2]
ALSO, I want to do a rotation camera effect that suffers from the same 0,0 issue. Blatantly showing up as the player and level rotating around some far off pivot point.
If a Transform Matrix can swiftly and functionally offset the 0,0 to the players location so that I can do all the camera effects and alterations. I think that may be the best way to go.
----Close to Conclusion----
In regards to Vespers answer. Would I then be able to tween the resulting transform?
If so then that completely answers my entire problem. If not, I have no clue how to get the result I want.
I think the container is the cleanest solution. Since it'll be centered on the player, rotations and scaling will work normally. You mention getting the coordinates for the nested MC is hard, but there is a built-in function to do exactly that: localToGlobal()
To get the player position in global coordinates, just do player.localToGlobal(new Point(0, 0)). This should return the Player's center in global coordinates. If your main container is not in global coordinates (because it's nested inside another transformed MC, for example), you can use the opposite function on the container to convert from global to local:
container.globalToLocal(player.localToGlobal(new Point(0, 0)))
Now you just need to center the container. That could also be used to simulate the camera movement. If you update the container position at every frame, it'll give the effect of the camera following the player.

Detecting point where two objects collide

I'm totally beginner in Flash and Actionscript so sorry if my questuon is stupid.
I have to make a platform game - I'm planning to write something like Icy Tower - my character is jumping from one platform to another to get to the top of a tower of something. And here is my problem - I want to allow the character to jump onto a platform only from the top, but if he collides with whe platform from the bottom, or from the side, I want him to bounce (I hope you understand what I want mean).
So, to do something like that, I need to be able to detect where exactly do these two objects collide - the only solutions that comes to my mind is to keep the coordinates of every platform in some array and compare them with the characeter's position evertime he jumps, but it just doesn't seem right. Is there an better way to solve this problem?
I will be grateful for any advice.
PS. Sorry for my English
You can make use of a game library like flixel, or flashpunk. They are both great.
Essentially, you will need to iterate over all objects that your character can collide with. You can make use of .hitTestObject() to roughly determine if your character is colliding with any of the objects. Thereafter you can then get the coordinates and dimensions of your character on the stage and compare them to the coordinates and dimensions of the hit object to determine directions.
So in psuedo code
for each (var platform:DisplayObject in platforms) {
if (character.hitTestObject(platform)) {
if (collideFromBottom || collideFromSide) {
// allow movement
}
if (collideFromTop) {
// stop downward velocity
}
break; // might as well, as you have detected the collision
}
}
CollideFromBottom would be comparing the top of your character with the bottom of the platform. Remember that as Sprites, both player and platform have [x,y] properties and [width,height], allowing you to determine coordinates.
P.S. this question should have been asked at gamedev.stackexchange.com
I'd recommend you to use a Physics Engine like Box2D(
behold the examples), instead of creating some hitTest colision based game from scratch.
The probability of you having serious code/design problems and leaving the project aside are big.
There's a lot of good tutorials on internet, here a good resource - Using Box2d to Create a Side Scrolling Game:
Part 1
Part 2