Page 1 of 2
parenting makes angle fail
Posted:
Fri Dec 02, 2005 5:28 pm
by Novice
Ok, why does this happen?
When i parent an actor that has this code:
- Code: Select all
int shooterangle;
shooterangle=direction(shooter.x,shooter.y,a.x,a.y);
animpos=shooterangle/22.5;
The animtion dosent follow the mouse like it should it shows some weird angles. BTW this works well when i unparent it.
I tried doing this
- Code: Select all
shooter.x=car.x;
then the angle works good but the shooter lags behind the car 5 pixels wich looks really bad.
Please help!
Posted:
Fri Dec 02, 2005 6:35 pm
by makslane
Note: the x, y coordinates are relative to parent, so, if your shooter and a actors don't have the parent don't will works.
In this case, you must use xscren and yscreen that are the screen coordinates regardless the parent.
So, try use:
- Code: Select all
shooterangle = direction(shooter.xscreen, shooter.yscreen, a.xscreen, a.yscreen);
Posted:
Sat Dec 03, 2005 10:07 am
by Novice
Thanks it worked perfectly!
I have a simmilar problem with my tires.I have three of them and they have this
- Code: Select all
//tire1
x=player.x+20;
//tire2
x=player.x;
//tire3
x=player.x-20;
The problem is that Tire 2 lags behind whenewer i move the player but Tires 1 and 3 work perfectly. I noticed that it lags by the amount i move the player
so if player is x+=5; Tire 3 will always be 5 pixels behind.
I hope i explaind it well. And again tanks for all your help.
Posted:
Sun Dec 04, 2005 10:22 am
by Novice
Anyone?
Posted:
Mon Dec 05, 2005 11:20 am
by makslane
Are the tire 2 code in the Draw Actor event?
Posted:
Mon Dec 05, 2005 11:58 am
by Novice
Yes it is. I tried it now its not just in my curent game.I tried it out on a new game i creted two actors: actor A with key down events for x-=5; and x+=5;
and actor B with draw actor event x=A.x;
And the same thing hapens, it lags behind. As i understand when you say B.x=A.x that should be it, not B.x=A.x-5 or B.x=A.x+5.
I will send you a .ged file if you want.
Sorry for being such a bore but it is realy geting on my nerves.
Posted:
Mon Dec 05, 2005 12:51 pm
by makslane
Please, send me this file.
Posted:
Mon Dec 05, 2005 4:44 pm
by Novice
I sent it
Posted:
Tue Dec 06, 2005 10:28 am
by ericdg
Can Novice or Makslane help me out.
I know I need to use animpos but I don't know how.
I used your script below
int shooterangle;
shooterangle=direction(shooter.x,shooter.y,a.x,a.y);
animpos=shooterangle/22.5;
But I don't know what anything means. I made 9 image files ranging from 40 degrees and one direction to 40 in the other. How do I put how many images it needs to use and how does it know where to start.
I have a car actor on top of two tire actors and when I drive it, the animation changes at all the wrong times.
Thanks guys, I'll get the hang of this yet.
Posted:
Tue Dec 06, 2005 1:25 pm
by ingsan
Posted:
Tue Dec 06, 2005 9:36 pm
by Novice
If the links dont explain it let me know il try to help out.
Posted:
Wed Dec 07, 2005 1:39 am
by ericdg
Yeah, I followed the links and I still can't figure it out. I just don't know what the 22.5 on your script is for, and how you can tell the script which image to put with which angle.
Novice, if you could just break down that script a little for me, I'd appreciate it.
I've got the basics of GE down, but I'm trying to learn the C scripting portion.
Thanks.
Posted:
Wed Dec 07, 2005 10:52 am
by Novice
Ok with int shooterangle you create a varibale that will hold the angle, you can use any name like int position or such.
With shooterangle=direction(shooter.x,shooter.y,a.x,a.y); you tell the computer that the angle is calculated using direction betwen two actors in this case shooter and a.
With animpos=shooterangle/22.5; you make animation change depending on the angle. I divide shooterangle with 22.5 because my animation has 16 frames so 360/22.5=16 for ex. if your animation is 360 degres rotation and has 10 frames you should divide the angle vith 36. 360/36=10 and so on.
If that dosent explain it fell free to ask again.
BTW i solved my lag problem, it is a bug that hapens when actor names begin with small letters so if you have the same problem just make the first letter capital ex. Player insted of player.
Posted:
Wed Dec 07, 2005 2:37 pm
by ericdg
I'm finally starting to understand it.
If my animation has 8 frames, then does the 8 frames need to rotate all 360 degrees, or is there a way to limit it?
My animation has 8 frames but only rotates 40 degrees to the left and right since I don't need anymore rotation.
Do I need to make 24 more frames blank for the other rotation angles I won't use?
I tried a animation with 36 frames covering all 360 degrees and it worked great, but I would rather not have to make all those extra frames if not needed.
Also, what do you think would be the best way to slow a car down. When I press right arrow to speed up using xvelocity=xvelocity +.1; and I let go the car continues at this speed.
I could set a collision with the ground to slow down the car when I let off the right arrow using xvelocity=xvelocity -.1; but when it stops going right it starts going left.
Posted:
Wed Dec 07, 2005 3:20 pm
by ericdg
Also, is there a way to limit how far apart on the y axis the tires go. On the x axis they stay the same thanks to your tip on the bug Novice, but on the y axis they seperate by hundreds of pixels at times.