Posted By
|
Message
|
eski
Registered 20/09/2009
Points 39
|
4th October, 2009 at 21:38:52 -
Hi there
I been checking out Construct, its bit buggy, crashed alot but i like one thing about it.
Everything, every movement is so smooth and window scrolling.
Like if you make a sprite and give it 8 directions movement then it has automatic 360 turns.
Is the way to make MMF object smooth like that ?
Cheers
n/a
|
Codemonkey Always Serious
Registered 06/11/2007
Points 164
|
4th October, 2009 at 22:11:04 -
Yeah it's called a little effort.
Uh, there's proabably a tutorial on it.
Edited by Codemonkey
You can log off any time you like, but you can't ever leave.
|
Pixelthief Dedicated klik scientist
Registered 02/01/2002
Points 3419
|
4th October, 2009 at 23:22:13 -
If you want to rotate the object in degrees, use the "angle" variable on an active object and it will be rotated. If you want to create a movement like the race car movement that works in 360 degrees, you need some programming knowledge, basic trigonometry, and common sense.
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456
|
MrMcFlurry
Registered 03/08/2009
Points 89
|
5th October, 2009 at 05:52:36 -
Such systems are often referred to as static movement engines, since they involve giving the object no default movements (leaving them with static movement) and instead manually code the objects movement with position variables and setting the objects x and y position values.
a quick example would be to have your object with the variables: XPos, YPos, x inertia, y inertia
(For this you need either floats or shifting up and down powers of 10 to avoid aliasing in the numbers, because MMF likes shifting things into ints. I prefer the power shifting.)
so, to start, i set the objects X/YPos AValues to it's current x and current y positions *100 (<- the power shift, 10 pixels in becomes an XPos of 1000)
next controls
repeat while up is held: minus 10 from y inertia
repeat while down is held: add 10 from y inertia
repeat while left is held: minus 10 from x inertia
repeat while right is held: add 10 from x inertia
(Edit numbers above to affect the rate of acceleration)
then position code
always: add 'y inertia' to 'YPos', add 'x inertia' to 'XPos'
and then
always: set x position to 'XPos/1000'(<-- the shift down to put the number back into normal range)
set y position to 'XPos/1000'
now, when you run it, your object will accelerate smoothly in the 4 directions, needing to overcome inertia before managing a turn.
have a go at this, if you have troubles, ask and i might just be able to knock up an example for you tomorrow
n/a
|
eski
Registered 20/09/2009
Points 39
|
5th October, 2009 at 13:54:15 -
ok, this worked. Its really smooth on 100 fps. Now i just have to put in the 360° degrees angle then i'm set.
n/a
|
MrMcFlurry
Registered 03/08/2009
Points 89
|
5th October, 2009 at 18:22:37 -
Well, for direction you can simply have the object look towards the direction of it's current inertia.
using the advanced direction object, i would do:
always: set angle to [advanced direction object] angle between 'XPos':'YPos' and 'XPos + inertiaX':'YPos + inertiaY'
expression would look like:
Direction( "Advanced Direction Object", XPos, YPos, XPos + inertiaX, YPos+inertiaY)
it'll always look in the direction it's moving then
this is a quick example that gives the a fairly decent effect.and might not have quite the feel you want, you'll have to be inventive for something different
By the way, you might notice that your object moves faster in diagonals that on straights, to fix you'd need to expand on the control events (didn't cover this before because i didn't want to overload you, but since you seem to have it sorted, here we are)
now, for each event, you'd want to have conditions for each key, so for up:
repeat while up is held
-repeat while down is NOT held
-repeat while left is NOT held
-repeat while right is NOT held: minus 10 from y inertia
so it will do the up movement if only up is pressed, you repeat that for the 4 primary directions, and then for the combinations
lets take for example, Up and Right
repeat while up is held
-repeat while down is NOT held
-repeat while left is NOT held
-repeat while right is held: minus 7 from y inertia, add 7 to x inertia.
so when right andup is pressed, a combination of up and right is performed, but at a reduced magnitude (7 instead of 10)
The number 7 is an approximation of putting the magnitude of acceleration 10 in a 45 degree angle (using magnitude*cos45 or magnitude*sin45, aka r*cosθ or r*sinθ ) , the value is actually something like 7.07106...etc. so 7 is close enough
Edited by MrMcFlurry
n/a
|
MrMcFlurry
Registered 03/08/2009
Points 89
|
5th October, 2009 at 18:27:14 -
Oh, just to clarify, r*cosθ will give you the horizontal magnitude and r*sinθ the vertical for given angle θ. can be useful.
n/a
|
eski
Registered 20/09/2009
Points 39
|
6th October, 2009 at 02:58:04 -
i dont seem to get the advanced direction to work.
This is the command i should set on the active item right.. ?
If Always -> Set angel : Direction( "Advanced Direction Object", XPos, YPos, XPos + inertiaX, YPos+inertiaY)
I get a syntax error with it.
The slowing down bit works well though..
n/a
|
MrMcFlurry
Registered 03/08/2009
Points 89
|
6th October, 2009 at 14:14:54 -
you have added the advanced direction object to the frame right?
n/a
|
eski
Registered 20/09/2009
Points 39
|
6th October, 2009 at 14:41:42 -
hehe.. yah..
i should put that code to the set angle on the active object right ?
n/a
|
MrMcFlurry
Registered 03/08/2009
Points 89
|
6th October, 2009 at 16:10:57 -
ah, you are referencing the object right?
would look more like this technically, where Xpos, Ypos, inertiaX, inertiaY are alterable values a-d on the object
event: always
action: object->scale/angle/set angle
expression: retrieve data from object -> advanced direction object -> distance and direction between two points -> float/long values (either, no difference, long's prolly more efficient) -> direciton between two points(x1,y1,x2,y2)
then your expression would be:
Direction( "Advanced Direction Object", xpos( "Active" ), Ypos( "Active" ), xpos( "Active" )+inertiaX( "Active" ),Ypos( "Active" )+inertiaY( "Active" ))
basically, telling it where to find the alterable values
n/a
|
eski
Registered 20/09/2009
Points 39
|
6th October, 2009 at 17:01:12 -
yeahh.. thats what i'm talking about
thanks
n/a
|
bigredron
Registered 07/04/2007
Points 299
|
7th October, 2009 at 12:15:36 -
I normally use a float value to move my objects. Work out how far it has to move per frame and add that value to the position float, then always set position relative to the float value. In MMf it rounds it up to an integer. Not sure what construct does but I imagine it owuld be the same.
n/a
|
MrMcFlurry
Registered 03/08/2009
Points 89
|
8th October, 2009 at 00:05:38 -
Aye, I mentioned you could do that or multiple/divide by powers of ten, as i did in the example. Doing floats has proven fiddly for me in the past, as you have to continually remember to put 0.x onto things and such. So i got into the habit of keeping things ints is all. either technique works,but I've generally had less(or rather no) buggy situations with the power method, no having to track own a missed float conversion etc.
all a matter of preference really.
n/a
|
bigredron
Registered 07/04/2007
Points 299
|
14th October, 2009 at 04:21:12 -
Well I use LUA for all my coding and calculations so its easier for me to just stick to floats.
n/a
|
Tharky
Registered 05/10/2009
Points 30
|
4th February, 2011 at 18:11:20 -
Originally Posted by bigredron Well I use LUA for all my coding and calculations so its easier for me to just stick to floats.
How? I kinda fail at coding with Lua Tried everything to make my object move in 8 directions, and I couldn't managed to do that.
Newbie in Lua +
5 year experience with MMF =
Still nothing...
|
|
|