Quantcast

Jump to content

» «
Photo

[CLEO/SA] Carousel - rotating platform

12 replies to this topic
KNN.
  • KNN.

    ▓▒░_watch yerself_░▒▓

  • Feroci
  • Joined: 09 Jul 2006
  • European-Union
  • Best Map 2013 "ViceCityStories PC Edition"

#1

Posted 17 June 2014 - 08:48 AM Edited by HackMan128, 18 June 2014 - 08:06 AM.

I need help with CLEO script. The script has created object let's say in 0, 0, 0 (to be simple) and when player jumps on it, he should rotate on this object with walking ability. This is my script:

 

// Carousel for GTA San Andreas script Created by HackMan128

{$CLEO .cs}

thread 'CAROUSEL'

const  
WHEEL = #gwforum1_LAe
INITI_X = 260.65 // Carousel X position
INITI_Y = -1820.2 // Carousel Y position
INITI_Z = -10.0 // Carousel Z position
SPEED = 0.35 // Motor speed
end 

:INIT 
while 8256: not player $PLAYER_CHAR defined 
wait 0
end
029B: [email protected] = init_object WHEEL at INITI_X INITI_Y INITI_Z 
Object.CollisionDetection([email protected]) = true 
01C7: remove_object_from_mission_cleanup_list [email protected]                                                     
goto @LOOP

:LOOP
wait 0
[email protected] += SPEED // motor  
if [email protected] >= 360.0 // prevent value by overflow
then [email protected] = 0.0
end
// Rotation
[email protected] *= -1.0 // invert rotation
0453: set_object [email protected] XYZ_rotation 0.0 0.0 [email protected] // wheel
0096: make [email protected] absolute_float
0087: [email protected] = [email protected] 
// Player position
00a0: store_actor $PLAYER_ACTOR position_to [email protected] [email protected] [email protected]
0509: [email protected] = distance_between_XY [email protected] [email protected] and_XY INITI_X INITI_Y  
// 05A4: get_angle_between_vectors_origin_to [email protected] [email protected] and_origin_to INITI_X INITI_Y store_to [email protected] // not working properly, bug with counting angles.
0AB1: call_scm_func @getZAngleBetweenPoints 4 from_XY [email protected] [email protected] and_XY INITI_X INITI_Y store_to [email protected] // Wesser's function
0061: [email protected] -= [email protected]  
gosub @GETANGLE

if
0179: actor $PLAYER_ACTOR colliding_with_object [email protected]   
then 
    gosub @TRIGONOMSTUFF
    0A96: [email protected] = actor $PLAYER_ACTOR struct
    000A: [email protected] += 0x14
    0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0 
    000A: [email protected] += 0x30   
    0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0 
    000A: [email protected] += 0x34 
    005F: [email protected] += [email protected] // add to player actor x position cosine from wheel angle
    005F: [email protected] += [email protected] // add to player actor y position sine from wheel angle 
    [email protected] += INITI_X
    [email protected] += INITI_Y  
    // Set player actor x pos and y pos in the 3d world   
    0A8C: write_memory [email protected] size 4 value [email protected] virtual_protect 1
    0A8C: write_memory [email protected] size 4 value [email protected] virtual_protect 1  
    // Set Angle of player and camera
    gosub @GETANGLE
    [email protected] -= SPEED
    0173: set_actor $PLAYER_ACTOR Z_angle_to [email protected] 
    // 015F: set_camera_position [email protected] [email protected] [email protected] rotation 0.0 0.0 180.0 
    end 
jump @LOOP    

:GETANGLE
// Get angle of player and camera
0176: [email protected] = object [email protected] Z_angle
0172: [email protected] = actor $PLAYER_ACTOR Z_angle
return

:TRIGONOMSTUFF   
0065: [email protected] -= [email protected]
02F6: [email protected] = cosine [email protected]
02F7: [email protected] = sine [email protected]
0069: [email protected] *= [email protected]
0069: [email protected] *= [email protected]
[email protected] += INITI_X
[email protected] += INITI_Y 
0065: [email protected] -= [email protected] // substract player actor X position
0065: [email protected] -= [email protected] // substract player actor Y position
return

// Wesser's function
:getZAngleBetweenPoints
0063: [email protected] -= [email protected]
0063: [email protected] -= [email protected]
0604: get_Z_angle_for_point [email protected] [email protected] store_to [email protected]
0AB2: ret 1 [email protected] 

I can walk along distance ® of this wheel, but can't walk along circumference.

The player always reset his position to current angle of the wheel.

Could somebody correct this formulas or make something else like

- attach player to object

- multiply player matrice with wheel matrice

 

One of the problem is why get_angle_between_vectors_origin_to won't work well with this when player want to get ride on the Carousel.

 

//EDIT:

Problems solved. I just forgot to substract angle get_angle_between_vectors_origin_to and wheel angle.


Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer

  • Feroci
  • Joined: 19 Aug 2006
  • Unknown
  • Contribution Award [Mods]

#2

Posted 17 June 2014 - 12:29 PM Edited by Wesser, 17 June 2014 - 01:22 PM.

You can simply call CPhysical::AttachEntityToEntity (0x0054D570) which will work for any entity, no matter what kind of type they are (untested):
const
    CHAR_PTR = [email protected]
    CAROUSEL_PTR = [email protected]
end
const
    ATTACH_POS_X = 0.0
    ATTACH_POS_Y = 0.0
    ATTACH_POS_Z = 0.0
    ATTACH_ROT_X = 0.0
    ATTACH_ROT_Y = 0.0
    ATTACH_ROT_Z = 0.0
end

[...]

0AA6: call_method 0x0054D570 struct CHAR_PTR num_params 7 pop 0 fRotZ ATTACH_ROT_Z fRotY ATTACH_ROT_Y fRotX ATTACH_ROT_X fOffsetZ ATTACH_POS_Z fOffsetY ATTACH_POS_Y fOffsetX ATTACH_POS_X pParentEntity CAROUSEL_PTR

KNN.
  • KNN.

    ▓▒░_watch yerself_░▒▓

  • Feroci
  • Joined: 09 Jul 2006
  • European-Union
  • Best Map 2013 "ViceCityStories PC Edition"

#3

Posted 17 June 2014 - 12:56 PM Edited by HackMan128, 17 June 2014 - 01:05 PM.

0A98: [email protected] = object $CAROUSEL struct
0A96: [email protected] = actor $PLAYER_ACTOR struct
0AA6: call_method 0x0054D570 struct [email protected] num_params 7 pop 0 fRotZ ATTACH_ROT_Z fRotY ATTACH_ROT_Y fRotX ATTACH_ROT_X fOffsetZ ATTACH_POS_Z fOffsetY ATTACH_POS_Y fOffsetX ATTACH_POS_X pEntityToAttach [email protected]

This isn't it, the object follows player, so it works like attaching object to actor.


Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer

  • Feroci
  • Joined: 19 Aug 2006
  • Unknown
  • Contribution Award [Mods]

#4

Posted 17 June 2014 - 01:24 PM

My bad, I shuffled the pointers.

KNN.
  • KNN.

    ▓▒░_watch yerself_░▒▓

  • Feroci
  • Joined: 09 Jul 2006
  • European-Union
  • Best Map 2013 "ViceCityStories PC Edition"

#5

Posted 17 June 2014 - 03:13 PM Edited by HackMan128, 18 June 2014 - 11:09 AM.

Screen getting crazy after this switch, I tried that before, so I won't report error if it would work.

 

Anyway, no one ever created such platform? I remember that LC team changed something after beta 2 and player never fall off train roof anymore, but I haven't original code of that and anyway, I just need rotating thing which not move.

 

 

//EDIT: Almost done :), I have corrected psychic, so now actor position won't reset when touched.

 

//EDIT 2:

Done, for now player can walk on the platform and the platform moving him while rotating. First post edited.

All bugs are fixed.

 

Thanks to Wesser for @getZAngleBetweenPoints function from this page: http://gtaforums.com...in-script-help/


goodidea82
  • goodidea82

    SA Modder

  • Members
  • Joined: 13 Jun 2013
  • Germany

#6

Posted 17 June 2014 - 06:32 PM

I like the idea. I hope to see also the Ferris wheel rotating someday---therfore some comments.

- Don't use global variables in cleo scripts.

- Don't update the angle of the carousel with an explicit increment because then the rotation speed will depend on the speed of the computer. Instead, compute the angle from a global timer value.

- It would be better if the position of the player would not be set explicitly by your code but would rather result from the physics engine. (this would enable more playability e.g. messing around with the system) However, I'm not sure the physics will be able to do it. Creating rotation by setting the angle may be the problem because the physics engine may interpret this just as a sequence of discrete angles rather than as rotation. You can search if there is a function that creates a rotation speed that results in rotation (in this case then angle would not have to be computed) If this doesn't work, then use Wesser's suggestion.


KNN.
  • KNN.

    ▓▒░_watch yerself_░▒▓

  • Feroci
  • Joined: 09 Jul 2006
  • European-Union
  • Best Map 2013 "ViceCityStories PC Edition"

#7

Posted 17 June 2014 - 06:35 PM Edited by HackMan128, 17 June 2014 - 06:49 PM.

Wesser's suggestion not works, I tested it in previous posts. This is only one known way to do this script properly.

There are no physic for this wheel, player stay in one place even when enter on the wheel. Using game engine? If it would be that simple, there would be no need to create codes like this.


goodidea82
  • goodidea82

    SA Modder

  • Members
  • Joined: 13 Jun 2013
  • Germany

#8

Posted 17 June 2014 - 07:07 PM

Just saw the video of it (fun music btw).

Perhaps proper physics is not worth the trouble for your purpose. These were thoughts I actually had a long time ago when I was thinking how to make a proper Ferris wheel. However, I don't have the time to do it, so I thought I share my thoughts here.


KNN.
  • KNN.

    ▓▒░_watch yerself_░▒▓

  • Feroci
  • Joined: 09 Jul 2006
  • European-Union
  • Best Map 2013 "ViceCityStories PC Edition"

#9

Posted 17 June 2014 - 07:10 PM

Better this than nothing. Why you are always dissatisfied?

Works? Works. What's the problem?

Anyway, I don't have any other ideas for that.


goodidea82
  • goodidea82

    SA Modder

  • Members
  • Joined: 13 Jun 2013
  • Germany

#10

Posted 17 June 2014 - 07:21 PM

I didn't intend to be rude. It does the job.


Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer

  • Feroci
  • Joined: 19 Aug 2006
  • Unknown
  • Contribution Award [Mods]

#11

Posted 26 June 2014 - 11:06 AM Edited by Wesser, 26 June 2014 - 11:29 AM.

I misread the part where you say explicitly you wanna control the player on carousel. You can enhance his movements by replacing the first snippet with the second:
[email protected] += SPEED
if
    [email protected] >= 360.0
then
    [email protected] = 0.0
end

[...]

gosub @GETANGLE
[email protected] -= SPEED
0173: set_actor $PLAYER_ACTOR Z_angle_to [email protected]
const
    DEG_TO_RAD = 0.017453
end

[...]

[email protected] = WHEEL_SPEED
0079: [email protected] += frame_delta_time * WHEEL_SPEED
005B: [email protected] += [email protected]
0656: limit_angle [email protected] store_to [email protected]

[...]

0A96: [email protected] = actor $PLAYER_ACTOR struct
0A8E: [email protected] = [email protected] + 0x0558 // CPed.m_fCurrentHeading
0A8D: [email protected] = read_memory [email protected] size 4 vp 0
0A8E: [email protected] = [email protected] + 0x055C // CPed.m_fTargetHeading
0A8D: [email protected] = read_memory [email protected] size 4 vp 0
if
0045:  [email protected] == [email protected]
then
    [email protected] *= DEG_TO_RAD
    0063: [email protected] -= [email protected]
    if
        [email protected] < -3.141592 // +1e-6
    then
        [email protected] += 6.283185
    end
    //0A8C: write_memory [email protected] size 4 value [email protected] virtual_protect 0
    0A8C: write_memory [email protected] size 4 value [email protected] virtual_protect 0
end

eugene89
  • eugene89

    Rat

  • Members
  • Joined: 08 Apr 2014
  • United-States

#12

Posted 27 June 2014 - 02:30 AM

Better this than nothing. Why you are always dissatisfied?

Works? Works. What's the problem?

Anyway, I don't have any other ideas for that.

 

Is it stable enough for release? Could you email me a copy of the script - looks handy!


KNN.
  • KNN.

    ▓▒░_watch yerself_░▒▓

  • Feroci
  • Joined: 09 Jul 2006
  • European-Union
  • Best Map 2013 "ViceCityStories PC Edition"

#13

Posted 04 July 2014 - 08:31 AM Edited by HackMan128, 04 July 2014 - 08:49 AM.

@Wesser

I pasted that code and nothing has changed, but makes problem when player is in exactly the same position as object.

Firstly I thought that these changes will rotate camera angle by adding proper value, so camera would stay in angle corresponding to the wheel angle.

 

I mean something like this

0373=0,set_camera_directly_behind_player

but this is useless in this case because player can't steering the camera.

 

@maurice96

Use code from the first post, where is the problem?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users