Page 1 of 4

did you know...few tips about objects

Posted: 13 Aug 2013, 14:13
by xbx
Hi..

So I've been having a quick look at the speedball title, and I spotted a few (probably not very well documented to say the least :mrgreen: ) things that could be used:
  • for attaching a marker to something (say, a ball), you don't have to change the position marker all the time. Instead
    you can write:

    Code: Select all

      <marker manialinkframeid="Frame_BallMarker" objectid="{{{G_BallObject.Id}}}"/>
    A marker can be attached to:
    pos = "x y z"
    playerlogin="bob"
    objectid="#124124124" (any CSmObject)
    landmarktag="{{{BlockPoles[0].Id}}}" (or any CSmLandmark)
  • You could be actually throwing the ball object around, instead of using rockets / lasers to pass.

    To do this, you have to add more info to the object when importing it in the importer.
    (see next post)

    and then, you have to either

    Code: Select all

     G_BallObject.Throwable = True;
                Player.ThrowSpeed = 10.;
    
    which will have the effect that the player carrying the ball will throw it instead of shooting when they left click.

    Or

    Code: Select all

     
    G_BallObject.Throwable = False;
    G_BallObject.SetPositionAndVel(Player.Postion + offset, Player.AimDirection * throwspeed);
    
    using say CSmModeEvent::EType::OnActionEvent,
    with Event.ActionSlot == CSmModeEvent::EActionSlots::Activable1
    (that is when the player presses '1' on the keyboard.)

Re: did you know...

Posted: 13 Aug 2013, 14:16
by steeffeen
thanks :clap:
please more of such information!
we would make way more cool stuff if you would just let us know how...

Re: did you know...

Posted: 13 Aug 2013, 14:28
by xbx
Sooo. to make the object "physical", so that it can bounce around:

Code: Select all

<Item Type="DynaObject" Collection="SMCommon">
	<Phy>
		<DynaPointModel	Center="0 0 0" Radius="0.2" Restitution= "0.5" Friction="0.5" GravityCoef="2" />
		<TriggerShape Type="AABB" min="-0.2 -0.2 -0.2" max="0.2 0.2 0.2"/>
	</Phy>
	<Vis>
		<Mesh 				File="Meshes/Ball.Mesh.gbx"/>
		<LightBallSimple 	Radius="2" sRgb="1 1 1" Pos="0 0 0"/>
	</Vis>
	<Pivots>
		<Pivot Pos="0 -0.5 0" />
	</Pivots>
</Item>

Re: did you know...

Posted: 13 Aug 2013, 14:47
by Emilieng
About the scripting side of dynamic objects...

In maniascript, the class describing dynamic objects is CSmObject.
When manipulating dynamic objects, the important thing to have in mind is that, at any moment, an object is in a given "status", namely
- OnPlayer
- OnAnchor
- InWorld
- Unspawned

To change the status of an object, use the corresponding method
- SetPlayer(CSmPlayer)
- SetAnchor(CSmObjectAnchor)
- SetPosition(Vec3) or SetPositionAndVel(Vec3, Vec3)
- SetUnspawned()

E.g. if a given item was previously "InWorld", a call to the method "SetAnchor" will change its status to "OnAnchor". In other words, calling more than one of these methods during the same frame is useless: only the last method call will be taken into account.

You can access the status of an object with the field Status, which returns a CSmObject::EStatus.
When the status is OnPlayer, the field Player gives you which player currently owns the object. Having this field Null is equivalent for the status not to be "OnPlayer".
When the status is OnAnchor, the field Anchor gives you which anchor currently holds the object. Having this field Null is equivalent for the status not to be "OnAnchor".

Here is a short description of what the various statuses mean.

"OnPlayer"
The object is linked to a player.
It is not present in the world - in other words, the object only exists "virtually".
If the field "Throwable" is set to True, then next time the player will use the "shoot" button (presumably, the left click of the mouse) the object will be thrown, which lead to 2 remarks
1. Its status will switch from "OnPlayer" to "InWorld",
2. The direction of the throw is given by the players aim, and the force by the field CSmPlayer.ThrowSpeed
A player throws all objects with the same speed. If the player owns several throwable objects, all of them will be thrown at the same time, with the same speed and the same direction.
When a player throws an object, he/she does not fires any projectile (like a rocket). He/She has to lift his/her finger and press the fire button again to do so.

"OnAnchor"
The object is linked to an anchor defined by the map. Physics does not apply here - the object does not move until its status changes to "InWorld". This presumably will be the status of objects at the beginning of the match if you want them to have a fixed position in the map.

"InWorld"
The object is somewhere in the world, visible, and subject just like us to the tough laws of physics. You can get the coordinates of an object with the field CSmObject.Position, and its velocity with CSmObject.Vel.
Any call to the method "SetPosition" or "SetPositionAndVel" will set the status of an object to "InWorld". The object is "teleported" at the given position, and the given speed vector will be applied. You will probably have to be careful not to set the position inside of a wall or somewhere not reachable.
If a player touches the object, it reacts like any other item by generating a PlayerTouchesItem event.
Notice that objects are not affected by special blocks such as trampolines or jump pads, and do not either bounce on players or other objects.

"Unspawned"
The object is nowhere, but can be accessed later on.

Re: did you know...

Posted: 13 Aug 2013, 15:26
by Darkminus
Hello :)
Thanks for these informations :clap: , you should make more "did you know..." topics :thx:

Re: did you know...

Posted: 13 Aug 2013, 16:41
by spaii
:thx: for all precisions :thumbsup:

Code: Select all

  <marker manialinkframeid="Frame_BallMarker" objectid="{{{G_BallObject.Id}}}"/>
Could we have more information on manialinkframeid ?

Re: did you know...

Posted: 13 Aug 2013, 17:17
by steeffeen
spaii wrote:

Code: Select all

  <marker manialinkframeid="Frame_BallMarker" objectid="{{{G_BallObject.Id}}}"/>
Could we have more information on manialinkframeid ?
http://forum.maniaplanet.com/viewtopic. ... 79&t=16793 :thumbsup:

Re: did you know...

Posted: 13 Aug 2013, 17:58
by spaii
:yes: :thx: steeffeen :thumbsup:

Re: did you know...

Posted: 13 Aug 2013, 18:59
by Rots
xbx wrote:You could be actually throwing the ball object around, instead of using rockets / lasers to pass.
Image

I'd like to see that :o

Re: did you know...

Posted: 13 Aug 2013, 19:05
by steeffeen
we are doing that the whole evening already :lol: