Page 2 of 2
Re: Getting started iphone help

Posted:
Fri Dec 09, 2011 4:48 am
by maker151
hey, whats wrong with this code, i cant get it to work
switch(jump_var)
{
case 0:
jump_var=1;
player.yvelocity=-15;
ChangeAnimation("player", "jump", FORWARD);
ChangeAnimationDirection("player", STOPPED);
break;
case 1:
jump_var=2;
ChangeAnimation("player", "double jump", FORWARD);
ChangeAnimationDirection("player", STOPPED);
player.yvelocity=-15;
break;
}
then i added this code
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000, 1.000000, 0.000000, 1.000000);
ChangeAnimation("player", "land", FORWARD);
jump_var = 0;
i added an animation finish event and it would not work or it would but in a weird way, what have i done wrong??
Re: Getting started iphone help

Posted:
Fri Dec 09, 2011 5:06 am
by skydereign
You're going to have to be more descriptive than that. What do you mean it would not work? Define weird. I assume that event (the one with the PhysicalResponse) is a collision no repeat enabled event?
Re: Getting started iphone help

Posted:
Sun Dec 18, 2011 10:21 am
by maker151
hey sorry for the wait laptop crashed, umm okay, ur assumption is correct, the part that goes wrong is when i land and the then change the animation to running the player goes into a weird spasm instead of landing and running. also, when i clone the planks on a basic array the physical response sometimes fails
Re: Getting started iphone help

Posted:
Sun Dec 18, 2011 10:38 am
by skydereign
Okay, well your collision code for setting the animation needs to set to not repeat. But, you'll also need a collision event with the PhysicalResponse that is set to repeat. The animation spasm problem you are having is due to that ChangeAnimation call being triggered every frame that they player collides with the ground. The falling through might be due to the direction of collision.
Re: Getting started iphone help

Posted:
Thu Dec 22, 2011 1:03 pm
by maker151
i set the change animation event not to repeat on the collision but it still spasms... y is that happening???
Re: Getting started iphone help

Posted:
Thu Dec 22, 2011 8:12 pm
by skydereign
Ah, I forgot your land animation is different than your run animation. Try this, you might need to adjust the yvelocity value depending on the gravity of your game.
- Code: Select all
if(yvelocity>3)
{
ChangeAnimation("player", "land", FORWARD);
}
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000, 1.000000, 0.000000, 1.000000);
jump_var = 0;
The idea is that if you are falling onto the platform, your yvelocity should be greater than 1 or 2, and you should change animation to land. Otherwise you should just have the collision event (no change animation). I usually use the state method, which would allow you to specify only change the animation if you are falling, but this should do the trick as well.
Re: Getting started iphone help

Posted:
Fri Dec 23, 2011 12:46 am
by maker151
hey thanks that worked well, how do i fix the random physical response failing. i dont know what to do for that
Re: Getting started iphone help

Posted:
Fri Dec 23, 2011 12:51 am
by skydereign
How fast is your actor moving? If it is moving faster than half the tile's width, then you can't fix it with PhysicalResponse. But, perhaps it is due to you not having collisions with the tile's left or right side. It's kind of hard to diagnose without seeing your game.
Re: Getting started iphone help

Posted:
Sat Dec 24, 2011 12:29 am
by maker151
ok, i added physical responses to left and right side but there was still no change, how do i fix that first problem u described, im not sure how to with out the physical response
Re: Getting started iphone help

Posted:
Sat Dec 24, 2011 5:48 am
by skydereign
Well actually it isn't quite as extreme as half the width, I forgot to factor in the actor itself. So, half the width of the tile, and half the width of the actor. Anything faster has the capability to fail. And there isn't a good fix for this. You can use larger tiles, create filled regions for collisions, or develop your own collision system. There are potentially even more little cheap things you can do to improve the chances of catching a collision, but nothing will be as concrete as you creating your own system. One usual fix is to prevent yvelocity from ever getting that high. You'd usually set the max to a comfortable distance less than that yvelocity. Is the player's yvelocity greater than half the sum of the player and tile's width? Otherwise you'll need to give me more to work with.
Re: Getting started iphone help

Posted:
Wed Dec 28, 2011 7:12 am
by maker151
its all good, i fixed the problem, i was wondering i searched and could not find anything on random actors generating along an array, to be specific, i need to randomize the x space(distance) but create my landing platforms on one consistent y coordinate while having different animations of the actor randomly chosen. also, im curious why did that "if statement" of the y velocity change the animation to work perfectly??
Re: Getting started iphone help

Posted:
Wed Dec 28, 2011 7:29 am
by skydereign
Pretty much anything random is done with the rand function. If you want to spawn things on the x axis, with random distances between them then you can do so by looping CreateActor with the same y, and a random x. For instance, you can do something like this.
- Code: Select all
int i;
for(i=0;i<20;i++)
{
CreateActor("actor", "anim", "(none)", "(none)", i*100+rand(50), height/2, false);
}
They'll be created at relatively uniform intervals, but have a random aspect. But, if you want truly random instead of progressively created, you can just use rand instead of the for loop.
actor.0 (000-050, 240)
actor.1 (100-150, 240)
actor.2 (200-250, 240)
actor.3 (300-350, 240)
and so on...
To have them have random animations you can add this event. All you'd need to change is num_of_animations to the actual number of animations the actor has.
actor -> Create Actor -> Script Editor
- Code: Select all
ChangeAnimation("Event Actor", getAnimName(rand(num_of_animations)), FORWARD);
Now, the if statement worked because when yvelocity is greater than whatever you set it to, that means the actor is falling. Because of the actor's gravity in its draw script, it will constantly be falling even while it is on the tiles, but it is also constantly colliding with the ground, and therefore reseting its yvelocity. If the actor was able to fall for 2-3 frames, then yvelocity would be greater than three, and therefore you would want a landing animation to activate. If the actor hadn't been falling for more than two frames, that means they have been running on tiles and you don't want to trigger the animation change.
Re: Getting started iphone help

Posted:
Wed Dec 28, 2011 10:46 am
by maker151
how do i implement each bit of code?
Re: Getting started iphone help

Posted:
Thu Dec 29, 2011 12:11 am
by skydereign
Which leads me to believe you don't know what the code is doing? I prefer having you understand the code, than me just giving it out. If you know a bit of code's function, you can figure out where it goes. That first bit creates 20 tiles spaced somewhat randomly about. Where would you want to spawn 20 randomly spaced tiles? You might put it in the view's create actor event, or a mouse button down event for a menu. In the case of the mouse button down event, you'd have to change the code a tad though. And the other bit of code I already told you where to put it.