Reply to this topicStart new topicStart Poll

» Making ice and perfect movement, Tutorial on making ice and good movement
lukas1121
Posted: Oct 18 2009, 02:27 PM
Quote Post
Desert Dash Champion!
Stick Avalanche Champion!




Member
**

Group: Members
Posts: 99
Joined: 10-February 08
Member No.: 31



Warn: (0%) -----


Download Example

start by making a sprite that will be the player and then make a sprite that will be the ice and a sprite that will be a block.

Now make an object for the player sprite.
Make a create event and in that one write.
CODE
// Ground Friction
frc = 0.5;
// Gravity
grv = 0.5;

// Face
face = 0

// Moving and collision detection
xspeed = 0;
yspeed = 0;


now those are all the variables you need to get started.
make a step event and place this code into it

CODE

x += xspeed;
y += yspeed;

if (xspeed < 0) {xspeed += frc; if (xspeed > 0) {xspeed = 0;}}
if (xspeed > 0) {xspeed -= frc; if (xspeed < 0) {xspeed = 0;}}
yspeed += grv;

if (keyboard_check(vk_right))
 {
 face = 0;
 if (xspeed < 4)
   {xspeed += 4*frc;}
 }
if (keyboard_check(vk_left))
 {
 face = 1;
 if (xspeed > -4)
   {xspeed -= 4*frc;}
 }

if (keyboard_check(vk_up))
 {
 if (!place_free(x, y+2))
   {yspeed = -8;}
 }

// Friction settings
if (instance_place(x, y+2, obj_Block))
 {frc = 0.5;}
else if (instance_place(x, y+2, obj_ice))
 {frc = 0.05;}
//else if (instance_place(x, y+2, <ANOTHER OBJECT TO APPLY FRICTION TO>))
 {frc = <YOUR FRICTION>;}*/
else
 {frc = 0.1;}
// Stops falling
if (!place_free(x, y+yspeed)) {yspeed = 0;}
// Prevent running into walls etc.
if (!place_free(x+xspeed, y)) {xspeed = 0;}


now we have made the player with movement gravity and the whole ice gliding thing. Now we need to make a block that we can walk on, make an object for the sprite of the block.
now tick it solid, now next make an object for the ice and tick it solid and give it the block as a parent. now just put it all into the game and it should work if done correct. heres a link if you cant make it work, you can just see this example

download GMK
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 

Lo-Fi Version
   Script Execution time: 0.3846    12 queries used    GZIP Enabled
Your last action was on: A minute ago