Rotation Problem

For questions about using Classic.

Post » Wed Aug 04, 2010 5:22 pm

http://dl.dropbox.com/u/9762772/Rotation%20Example.cap
Can't remember what ver. of Construct I have.

First post :D

Anyways, I'm trying to make a rotation that will smoothly rotate
towards an angle. By "smoothly", I mean that it will rotate towards
an angle, then decelerate the more it comes closer to matching that
specified angle.

So I got something working. I use two objects, one always points
towards the specified angle(The mouse position), and Object 2
will rotate to match Object 1.

I get the speed at which Object 2 will rotate by taking the 2 separate angles
and getting the difference between the two, scale that difference
towards a reasonable "speed" that I want it to rotate at, and then
incorporate that "speed" into an event.

The problem with this is that the Object 2 will suddenly accelerate
once Object 1 hits 360 and snaps back to 0, then return to a normal
speed after it also crosses that snap.

So, is there a way to fix this, or is there an easier way to
get the kind of rotation I want?

Been wrapping my brain around this for a while, but I can't come up with anything.
Cap is a little messy, but I hope it isn't unreadable.
Thanks for reading!

EDIT: Typos.
B
12
S
2
G
4
Posts: 44
Reputation: 2,389

Post » Wed Aug 04, 2010 6:59 pm

The "anglediff(a, b)" expression is a better way to calculate angle differences as is corrects for the 360 to 0 jump.

Change this
[code:3gwp2r86]-> Sprite16: Set 'Angle Speed' to Sprite16.Angle - Sprite162.Angle[/code:3gwp2r86]
to this
[code:3gwp2r86]-> Sprite16: Set 'Angle Speed' to anglediff(Sprite16.Angle, Sprite162.Angle)[/code:3gwp2r86]
and remove event 3
B
79
S
24
G
54
Posts: 4,749
Reputation: 40,761

Post » Thu Aug 05, 2010 5:59 pm

This is a really useful piece of code!

Might I also suggest that you change the '30' in your events to a private variable (I just called it Rotate Speed while playing around with the cap) and then you can quickly fine tune the speed at which your sprite rotates - with 1 being immediate rotation and larger values delaying it.

Oh and wouldn't something need to be scaled by delta time here?
B
15
S
6
G
6
Posts: 103
Reputation: 2,968

Post » Thu Aug 05, 2010 7:41 pm

[quote="untune":zrmy4w9d]Oh and wouldn't something need to be scaled by delta time here?[/quote:zrmy4w9d]

time delta isnt actually needed, its something you add for a desired reaction to lag and refresh rate independance.

in this case id imagine you'd need to scale the rotation speed, and thats it.

time delta makes your game "choppy" when it lags, instead of being "slow-mo", which can cause serious problems with collision detection, one reason i avoid using it. an advantage to using it though is that your game can be monitor independent if its using VSYNC, but really, you could just make your game have a fixed 60fps version and a vsync version for 60 Hertz screen users. i think its just as good a solution, seeing as most people have a 60 htz screen anyways.
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Thu Aug 05, 2010 7:50 pm

Oh yeah, I just thought it was good practice to use it in any custom (or rather non-behaviour based) movement in Construct?
B
15
S
6
G
6
Posts: 103
Reputation: 2,968

Post » Thu Aug 05, 2010 9:21 pm

[quote="untune":5th10p2l]Oh yeah, I just thought it was good practice to use it in any custom (or rather non-behaviour based) movement in Construct?[/quote:5th10p2l]

well as i said, theres no bad about using either, only different advantages.
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Fri Aug 06, 2010 9:21 pm

Thanks alot, R0J0hound, really saved the day for me!

[quote="untune":3ra8gguk]This is a really useful piece of code!

Might I also suggest that you change the '30' in your events to a private variable (I just called it Rotate Speed while playing around with the cap) and then you can quickly fine tune the speed at which your sprite rotates - with 1 being immediate rotation and larger values delaying it.

Oh and wouldn't something need to be scaled by delta time here?[/quote:3ra8gguk]

The 30 in the cap was going to be replaced by a private variable later on,
as the example I posted was going to be grafted into my project when
I had gotten what I wanted done with the rotation, and optimized it some.
It's now 4 actions in an "always" event.

Code if you want it;

[code:3ra8gguk]

Always;

Object1 -> Set Position to Object2
Object1 -> Set Angle toward (mouseX,mouseY)
Object1 -> Set variable "RSpeed" to anglediff(Object1.Angle,Object2.Angle)
Object2 -> Rotate Object1.Value('RSpeed')/10 degrees toward (mousex,mousey)
[/code:3ra8gguk]

Thanks for looking at it guys, I really appreciate it!
B
12
S
2
G
4
Posts: 44
Reputation: 2,389


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest