Custom movement

Get help using Construct 2

Post » Mon Sep 07, 2015 7:44 pm

Hello fellow constructers =)

Im new to construct and im enjoying it a lot, awesome tool, i already did some tutorials and im starting to getting the hook of it, and honestly got some practice with scripting (School). I wanted to emulate the move behavior of one of my favourite games ever, Ultima 7 (yeah! i know its awesome), for those who dont know ill explain:

-theres a mouse
-the mouse icon changes depending of the position around the player and the distance, the more near the slower, the more far the quicker
-the player sprite move in the mouse direction while mouse is clicking, so if you are clicking and move mouse the direction would change

I felt its harder than i think or could achieve alone, so if anyone could help me i would glady apreciate.

Thank you and sorry for my english, i know its bad =(
B
3
G
2
Posts: 11
Reputation: 697

Post » Mon Sep 07, 2015 9:10 pm

Moving to a mouse click is easy. You can create instance variables. mouseX, and mouseY on the player. When the mouse is clicked you can set those values to Mouse.X, and Mouse.Y. Then you can create an event that will move the player to that position.

Make sure the mouse object is in the layout..

If you don't mind if they lerp there then:
set position event
in the x box
lerp(player.X, player.mouseX, 1 - 0.5 ^ dt)
in the y box
lerp(player.Y, player.mouseY, 1 - 0.5 ^ dt)

The mouse icon would be pretty easy too.

for the event you would do the cog wheel compare two values distance(player.X, player.Y, mouse.X, mouse.Y) <= x
set cursor to this image.. then you do another event for the second image.
X in this instance is replaced by the distance in pixels.

If you want the player to move fast when clicking far away... you can do an event.. if distance from
player.mouseX, player.mouseY > x
then lerp(player.X, player.mouseX, 1 - 0.3 ^ dt) -- see here 0.5 became 0.3, which is a quicker speed.
Do the same for setting player Y...

that number can't be greater than of equal to 1... so 0.1 - 0.9 the lower the number the faster the lerp... if you find lerp isn't working for you there is LiteTween, which is a custom plugin you can get here:

behavior-litetween_t70700

It's like lerp, but a little more to it..

Please forgive if the math is a little off, but I think this will work, and a good starting point to experiment with in the least..
B
7
S
2
Posts: 92
Reputation: 663

Post » Mon Sep 07, 2015 11:34 pm

WOW! gotta test it! it looks complicated but intuitive at same time, thanks a lot for the help, ill try to see if i can do it.

Thanks a lot
B
3
G
2
Posts: 11
Reputation: 697

Post » Tue Sep 08, 2015 12:43 am

The problem is if you have animations you'll need to find a way to know which direction the sprite is moving in to work accordingly. One issue is I'm not sure how you want to let the player move. This method will let the player move almost anywhere, kind of like gliding there. You'll need to set that with animations if you're okay with that.. But if it's like the old old Ultima games, you would need to do something else, like only allowing four direction move..

What I put above might not even be what you're looking for :(
B
7
S
2
Posts: 92
Reputation: 663

Post » Tue Sep 08, 2015 12:56 am

You might want to consider using path finding to. The problem you're going to face with lerping sprites around is working around collision objects like walls... if you use the lerp method, and click outside a building, your sprite isn't going to care if it's going through a wall or not... If you use path finding instead it may be a bit easier, and you can use the same method... set the walls as obstacles, and the player should find a way through there, through a door, but not a closed one... You can just stop his path walk if he bumps into something :) that might be better for you..

What you would do is add path-finding behavior to your character. On click find path... then next event.. on path found.. start following path... Not sure if that needs to be every tick or not.. Just test it without first... You can set acceleration based on distance.. new event, the cogwheel compare two values... the first value will be distance(player.mouseX, player.mouseY, player.X, player.Y) < 10 then set acceleration slower... if 20 or whatever, set acceleration higher...

mouseX and mouseY are instance variables like before attached to your player, you attach them yourself as a number..

On start of layout event... set all your obstacles in path finding..

A crucial step is to set cell size. You do this in the layout window after clicking your path-finding sprite. To the left.. find cell size and set it to roughly the size of your box the sprite is in.. should be something like 32, 64... not sure about rectangles.. but I find having the cell size as close to the box size, or a tiny pinch smaller works best..
B
7
S
2
Posts: 92
Reputation: 663

Post » Tue Sep 08, 2015 1:28 am

Ok thats a lot of information =) i gotta do a lot of testing, should focus in step by step, first changing the mouse, then movement, and finally speed of character, but that was a lot of help Jeremy, thanks =)
B
3
G
2
Posts: 11
Reputation: 697

Post » Tue Sep 08, 2015 7:43 am

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,882

Post » Tue Sep 08, 2015 11:59 am

Thats awesome! nice coding really like it! thanks a lot =)
B
3
G
2
Posts: 11
Reputation: 697


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 28 guests