Vice City Multiplayer

VC:MP 0.4 (Beta) => Script Discussion => Topic started by: Honey. on October 02, 2014, 01:44:23 pm

Title: Rotating Sprites
Post by: Honey. on October 02, 2014, 01:44:23 pm
Hello,

I needed help in rotating sprites.I am trying to use SetRotationForPlayer( player, rotation ) but i get no errors and nothing happens.

I try to rotate it like this :

Code: [Select]
s <-CreateSprite( "spritename.png", 500, 600, 0, 0, 0,255 );
s.ShowForPlayer( FindPlayer( player ) );
s.SetRotationForPlayer(player, 150);
Title: Re: Rotating Sprites
Post by: Flockshot on October 02, 2014, 03:31:46 pm
Hmm i also have this error but it shows error in console
Saying that cannot find member variable
Title: Re: Rotating Sprites
Post by: tђยภ๔єгรt๏г๓ on October 02, 2014, 03:54:18 pm
Code: [Select]
s.RotateForPlayer(player, 150);
Title: Re: Rotating Sprites
Post by: Honey. on October 02, 2014, 05:08:00 pm
That function does rotate the sprite but doesn't rotate the sprite I want but instead makes a new sprite and rotates that!

Multiple Sprites was a bug of my script which i fixed later but now there is a new problem.The needle's position keeps changing on the screen while moving.If my car stays still it doesn't move but If my car is not still it dances on the screen.
Title: Re: Rotating Sprites
Post by: sseebbyy on October 02, 2014, 05:49:54 pm
Maybe because you rotate the sprite when position is changed ?! (or in a speedometer script?)
Title: Re: Rotating Sprites
Post by: Honey. on October 02, 2014, 05:59:14 pm
Maybe because you rotate the sprite when position is changed ?! (or in a speedometer script?)

If you mean the position of the player is changed then you're right.The player position is contantly changing while  it is driving.
Title: Re: Rotating Sprites
Post by: thijn on October 02, 2014, 08:06:15 pm
Post some more code. A sprite doesn't dance on your screen unless you tell it to.
Title: Re: Rotating Sprites
Post by: Honey. on October 03, 2014, 05:33:15 am
Post some more code. A sprite doesn't dance on your screen unless you tell it to.

Here you go :

Code: [Select]

function onScriptLoad()
{
// Other Functions
NewTimer( "Speedometer", 1500, 0 );
s <-CreateSprite( "needle.png", 500, 500, 0, 0, 0,255 );
// other functions
}

function Speedometer()
{
for ( local i = 0; i < GetMaxPlayers(); i++ )
{
                local p = FindPlayer( i );
                if ( p )
                {
                        if ( p.IsSpawned )
                        {
                                local vehicle = p.Vehicle;
                                if ( vehicle )
                                {
                          local Speed = sqrt(vehicle.Speed.x*vehicle.Speed.x + vehicle.Speed.y * vehicle.Speed.y + vehicle.Speed.z * vehicle.Speed.z) * 50 * 3.6;
                          local output = round(Speed, 0);
  s.RotateForPlayer( p, output );
                                }
                        }
                }
         }
}

function onPlayerEnterVehicle( player, veh, isPassenger )
{
s.ShowForPlayer( player );
}
function onPlayerExitVehicle( player, veh )
{
s.HideFromPlayer( player );
}

This is all of the code I have used.
Title: Re: Rotating Sprites
Post by: Honey. on October 03, 2014, 09:11:08 am
Here is a video ( sorry for the bad quality, I compressed the video too much  :-\ ) :

(http://i1368.photobucket.com/albums/ag163/honeyr697/th_Needle_zpsca08ea00.mp4) (http://i1368.photobucket.com/albums/ag163/honeyr697/Needle_zpsca08ea00.mp4)

Title: Re: Rotating Sprites
Post by: Honey. on October 03, 2014, 04:55:10 pm
Bump!!
Title: Re: Rotating Sprites
Post by: stormeus on October 03, 2014, 10:23:37 pm
The sprites are fine, the problem is your math. Objects are rotated about an axis of 360 degrees. If a player is going 1km/h, your sprite rotates 180 degrees. If a player is going 2km/h, your sprite rotates 360 degrees. It will only rotate to 0 or 180 degrees or some derivative of it, and especially because you round to the nearest whole number.
Title: Re: Rotating Sprites
Post by: Honey. on October 04, 2014, 07:36:20 am
The sprites are fine, the problem is your math. Objects are rotated about an axis of 360 degrees. If a player is going 1km/h, your sprite rotates 180 degrees. If a player is going 2km/h, your sprite rotates 360 degrees. It will only rotate to 0 or 180 degrees or some derivative of it, and especially because you round to the nearest whole number.

Can you explain more? I didn't quite understand what you meant.

Secondly rotation problems is a different case why does the sprite move in random positions?
Title: Re: Rotating Sprites
Post by: stormeus on October 04, 2014, 07:44:30 am
The sprites are fine, the problem is your math. Objects are rotated about an axis of 360 degrees. If a player is going 1km/h, your sprite rotates 180 degrees. If a player is going 2km/h, your sprite rotates 360 degrees. It will only rotate to 0 or 180 degrees or some derivative of it, and especially because you round to the nearest whole number.

Can you explain more? I didn't quite understand what you meant.

I don't know how to explain this any further without having to teach trigonometry.

Quote
Secondly rotation problems is a different case why does the sprite move in random positions?

I'm going to say because you didn't remove whitespace/transparency around the speedometer sprite.
Title: Re: Rotating Sprites
Post by: Honey. on October 04, 2014, 08:02:11 am
Is whitespace created when we enter in the vehicle by pressing the enter button? I read that  :

Quote
Vertical white space is a bit more varied as to how it is encoded,but the most obvious in typing is the ↵ Enter result which creates a 'newline' code sequence in applications programs

Where is the whitespace created and how do I remove it?
Sorry for being a noob here  ;)
Title: Re: Rotating Sprites
Post by: stormeus on October 04, 2014, 09:17:23 am
Whitespace is created when you have a PNG with transparency around the image.