Quantcast

Jump to content

» «
Photo

[CLEO/SA] Carousel - rotating platform

12 replies to this topic
HM128
  • HM128

    alovelyday

  • Feroci
  • Joined: 09 Jul 2006
  • None
  • 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: 0@ = init_object WHEEL at INITI_X INITI_Y INITI_Z 
Object.CollisionDetection(0@) = true 
01C7: remove_object_from_mission_cleanup_list 0@                                                     
goto @LOOP

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

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

:GETANGLE
// Get angle of player and camera
0176: 23@ = object 0@ Z_angle
0172: 24@ = actor $PLAYER_ACTOR Z_angle
return

:TRIGONOMSTUFF   
0065: 21@ -= 22@
02F6: 14@ = cosine 21@
02F7: 15@ = sine 21@
0069: 14@ *= 25@
0069: 15@ *= 25@
26@ += INITI_X
27@ += INITI_Y 
0065: 14@ -= 26@ // substract player actor X position
0065: 15@ -= 27@ // substract player actor Y position
return

// Wesser's function
:getZAngleBetweenPoints
0063: 0@ -= 2@
0063: 1@ -= 3@
0604: get_Z_angle_for_point 0@ 1@ store_to 4@
0AB2: ret 1 4@ 

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

#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 = 0@
    CAROUSEL_PTR = 1@
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

HM128
  • HM128

    alovelyday

  • Feroci
  • Joined: 09 Jul 2006
  • None
  • Best Map 2013 "ViceCityStories PC Edition"

#3

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

0A98: 0@ = object $CAROUSEL struct
0A96: 1@ = actor $PLAYER_ACTOR struct
0AA6: call_method 0x0054D570 struct 0@ 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 1@

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

#4

Posted 17 June 2014 - 01:24 PM

My bad, I shuffled the pointers.

HM128
  • HM128

    alovelyday

  • Feroci
  • Joined: 09 Jul 2006
  • None
  • 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

#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.


HM128
  • HM128

    alovelyday

  • Feroci
  • Joined: 09 Jul 2006
  • None
  • 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

#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.


HM128
  • HM128

    alovelyday

  • Feroci
  • Joined: 09 Jul 2006
  • None
  • 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

#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

#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:
20@ += SPEED
if
    20@ >= 360.0
then
    20@ = 0.0
end

[...]

gosub @GETANGLE
24@ -= SPEED
0173: set_actor $PLAYER_ACTOR Z_angle_to 24@
const
    DEG_TO_RAD = 0.017453
end

[...]

19@ = WHEEL_SPEED
0079: 19@ += frame_delta_time * WHEEL_SPEED
005B: 20@ += 19@
0656: limit_angle 20@ store_to 20@

[...]

0A96: 10@ = actor $PLAYER_ACTOR struct
0A8E: 11@ = 10@ + 0x0558 // CPed.m_fCurrentHeading
0A8D: 13@ = read_memory 11@ size 4 vp 0
0A8E: 12@ = 10@ + 0x055C // CPed.m_fTargetHeading
0A8D: 14@ = read_memory 12@ size 4 vp 0
if
0045:  13@ == 14@
then
    19@ *= DEG_TO_RAD
    0063: 13@ -= 19@
    if
        13@ < -3.141592 // +1e-6
    then
        13@ += 6.283185
    end
    //0A8C: write_memory 11@ size 4 value 13@ virtual_protect 0
    0A8C: write_memory 12@ size 4 value 13@ virtual_protect 0
end

maurice96
  • maurice96

    _Caspboy_

  • 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!


HM128
  • HM128

    alovelyday

  • Feroci
  • Joined: 09 Jul 2006
  • None
  • 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