Page 1 of 1
The distance covered in space changes when rotating with RotateEntity ()
Posted: Sat May 01, 2021 8:22 am
by tft
The first problem was hardly solved. The next one is already around the corner.
I move my entity with the ApplyEntityImpulse () command. It works as it should. In addition, the entity is set with the RotateEntity (). The entity moves faster through the room. However, the linear speed does not change. The distance covered simply increases. This is visually noticeable through faster movement. The faster the linear speed, the greater the effect.Every 5 frames I calculate the distance covered. And that confirms this behavior.
Any ideas??
Re: The distance covered in space changes when rotating with RotateEntity ()
Posted: Sat May 01, 2021 4:35 pm
by pf shadoko
I didn't understand your explanations
that said, personally, (but I may be wrong), when I use physics on an entity, I only use physiqye (no moveentity, rotateentity, ...)
(I don't know how the physics engine handles this double constraint)
to rotate you can use ApplyEntityTorque
but it's more complicated to manage
it's up to you
Re: The distance covered in space changes when rotating with RotateEntity ()
Posted: Wed May 05, 2021 9:38 am
by tft
Hello, there is no one here who can tell me why when mixing physics motion with rotate functions. The effective distance covered is greater? And how can that be prevented?
Re: The distance covered in space changes when rotating with RotateEntity ()
Posted: Wed May 05, 2021 10:06 am
by pf shadoko
Can you make a minimal example where your problem appears?
Re: The distance covered in space changes when rotating with RotateEntity ()
Posted: Thu May 06, 2021 10:28 am
by tft
I am looking for an example.
Re: The distance covered in space changes when rotating with RotateEntity ()
Posted: Thu May 06, 2021 10:53 am
by tft
With this code section I calculate the distance covered every 5 frames.
Code: Select all
;- Kalkulation der zurück gelegten Streck
If CalkCount < 5 ;-- Durchlaufzähler für CalkCount
CalkCount = CalkCount + 1
Else
CalkCount = 1
EndIf
If CalkCount = 1 ;-- Die Start Position wird gespeichert
Define p_posx1.f = EntityX(ObjAnkerPlayer)
Define p_posy1.f = EntityY(ObjAnkerPlayer)
Define p_posz1.f = EntityZ(ObjAnkerPlayer)
;ElseIf CalkCount = 2
ElseIf CalkCount = 5
Define p_posx2.f = EntityX(ObjAnkerPlayer)
Define p_posy2.f = EntityY(ObjAnkerPlayer)
Define p_posz2.f = EntityZ(ObjAnkerPlayer)
GeflogeneDistance.f = Sqr(Pow( p_posx1.f - p_posx2.f ,2) + Pow( p_posy1.f - p_posy2.f ,2) + Pow( p_posz1.f - p_posz2.f ,2)) ;-- Distanz berechnung zwischen 2 Frames
Debug StrF(GeflogeneDistance.f)
;-- Hier wird die Vektor geschwindigkeit auf 0 gesetzt.
; Füe alle Richtungen. Wenn die zurückgelegte Entfernung pro abtastung
; kleiner ist ols 0.001 , somit kann absuluter Stilstand erreicht werden.
If GeflogeneDistance.f < 0.001
EntityVelocity(ObjAnkerPlayer,0,0,0)
EndIf
EndIf
And with that I control the ship in 3D space
Code: Select all
;- >> PROVISORISCH KAMERA STEUERUNG
If KeyboardPushed(#PB_Key_Pad7) : RotateNode(cameraAnkerY,0,-0.5,0,#PB_Relative) : EndIf
If KeyboardPushed(#PB_Key_Pad9) : RotateNode(cameraAnkerY,0,0.5,0,#PB_Relative) : EndIf
If KeyboardPushed(#PB_Key_Pad8) : RotateNode(cameraAnkerX,-0.5,0,0,#PB_Relative) : EndIf
If KeyboardPushed(#PB_Key_Pad5) : RotateNode(cameraAnkerX,0.5,0,0,#PB_Relative) : EndIf
;- << PROVISORISCH ENDE
If ImSchiff = 0 ;- Der Spieler ist nicht im Schiff ( Aussenansicht Steuerung )
If KeyboardPushed(#PB_Key_A) : RotateEntity(ObjAnkerPlayer,0,0,0.3,#PB_Relative ) : EndIf
If KeyboardPushed(#PB_Key_D) : RotateEntity(ObjAnkerPlayer,0,0,-0.3,#PB_Relative ): EndIf
If KeyboardPushed(#PB_Key_W) : RotateEntity(ObjAnkerPlayer,0.3,0,0,#PB_Relative ) : EndIf
If KeyboardPushed(#PB_Key_S) : RotateEntity(ObjAnkerPlayer,-0.3,0,0,#PB_Relative ): EndIf
ShipSpeed = 0
Else ;- Der Spieler ist im Schiff ( Schiff Stuern )
If KeyboardPushed(#PB_Key_A) : RotateEntity(ObjAnkerPlayer,0,0,0.3,#PB_Relative ) : EndIf
If KeyboardPushed(#PB_Key_D) : RotateEntity(ObjAnkerPlayer,0,0,-0.3,#PB_Relative ): EndIf
If KeyboardPushed(#PB_Key_W) : RotateEntity(ObjAnkerPlayer,0.3,0,0,#PB_Relative ) : EndIf
If KeyboardPushed(#PB_Key_S) : RotateEntity(ObjAnkerPlayer,-0.3,0,0,#PB_Relative ): EndIf
EndIf
If KeyboardPushed(#PB_Key_Add) ;- Schiff Beschleunigen in sicht richtung
ShipSpeed = ShipSpeedMax.f
ApplyEntityImpulse(ObjAnkerPlayer,EntityDirectionX(ObjAnkerPlayer)*ShipSpeed,EntityDirectionY(ObjAnkerPlayer)*ShipSpeed,EntityDirectionZ(ObjAnkerPlayer)*ShipSpeed,0,0,0 )
SetEntityAttribute(ObjAnkerPlayer, #PB_Entity_LinearSleeping , 0.001) ; das automatische deaktivieren der Physik berechnung für das Bewegen runter geschraubt
ElseIf KeyboardPushed(#PB_Key_Pad0) ;- Bremsen entgegen der Schiff Richtung ( Bremsschub )
ShipSpeed = ShipSpeedMax.f
ApplyEntityImpulse(ObjAnkerPlayer,EntityDirectionX(ObjAnkerPlayer)*-ShipSpeed,EntityDirectionY(ObjAnkerPlayer)*-ShipSpeed,EntityDirectionZ(ObjAnkerPlayer)*-ShipSpeed,0,0,0 )
SetEntityAttribute(ObjAnkerPlayer, #PB_Entity_LinearSleeping , 0.001) ; das automatische deaktivieren der Physik berechnung für das Bewegen runter geschraubt
Else
ShipSpeed = 0
EndIf
I'll see if I can get my program cut down so that I can post it
Re: The distance covered in space changes when rotating with RotateEntity ()
Posted: Thu May 06, 2021 6:08 pm
by tft
Here is the link to a source code. The speed display shows the difference visually. Due to the calculation errors, it fidgets a bit. But the faster you move through space. The greater the difference can be seen. The debugger outputs the numbers.
https://www.sourcemagic.ch/SMGC/SMGC.zip
Re: The distance covered in space changes when rotating with RotateEntity ()
Posted: Fri May 07, 2021 10:21 am
by pf shadoko
Hi,
I looked into it, but I don't have enough time.
Also, I don't speak German
the problem doesn't necessarily come from "rotateentity".
Maybe it's a problem of double constraint
two attached objects to which you impose contradictory movements
your code seems to me a bit complicated
I put on the forum a mini simulator
maybe it could help you
viewtopic.php?f=36&t=72732
Re: The distance covered in space changes when rotating with RotateEntity ()
Posted: Sat May 08, 2021 12:56 am
by tft
ooo ... this Plane Simulator works cool..